From 4c856b3e3167ca1c23f54bddbce7eff8eb3dc20a Mon Sep 17 00:00:00 2001 From: Peinthor Rene Date: Wed, 15 Feb 2012 22:12:00 +0100 Subject: [PATCH] correctly close and save the application state --- src/mainwindow.cpp | 16 +++++++--------- src/mainwindow.h | 4 +++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8e41fcf6..0f0a6c48 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -549,7 +549,7 @@ void MainWindow::setupUi() retranslateUi(); - QObject::connect(fileExitAction, SIGNAL(activated()), this, SLOT(fileExit())); + QObject::connect(fileExitAction, SIGNAL(triggered()), this, SLOT(close())); QObject::connect(fileOpenAction, SIGNAL(activated()), this, SLOT(fileOpen())); QObject::connect(fileNewAction, SIGNAL(activated()), this, SLOT(fileNew())); QObject::connect(fileCloseAction, SIGNAL(activated()), this, SLOT(fileClose())); @@ -891,12 +891,6 @@ void MainWindow::init() void MainWindow::destroy() { - // this should be put into the close event but for now it is ok. - QSettings settings(QApplication::organizationName(), g_sApplicationNameShort); - settings.setValue("MainWindow/geometry", saveGeometry()); - settings.setValue("MainWindow/windowState", saveState()); - settings.setValue("SQLLogDock/Log", logWin->comboLogType()->currentText()); - if (gotoValidator){ delete gotoValidator; } @@ -1092,12 +1086,16 @@ void MainWindow::fileExit() } db.close(); } - QApplication::exit( 0 ); } -void MainWindow::closeEvent( QCloseEvent * ) +void MainWindow::closeEvent( QCloseEvent* event ) { + QSettings settings(QApplication::organizationName(), g_sApplicationNameShort); + settings.setValue("MainWindow/geometry", saveGeometry()); + settings.setValue("MainWindow/windowState", saveState()); + settings.setValue("SQLLogDock/Log", logWin->comboLogType()->currentText()); fileExit(); + QMainWindow::closeEvent(event); } void MainWindow::addRecord() diff --git a/src/mainwindow.h b/src/mainwindow.h index aa35cb92..7c206882 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -155,6 +155,9 @@ private: void setCurrentFile(const QString& fileName); void activateFields(bool enable = true); +protected: + void closeEvent(QCloseEvent *); + public slots: virtual void on_tree_context_menu(const QPoint & qPoint); virtual void on_tree_selection_changed(); @@ -169,7 +172,6 @@ public slots: virtual void resetBrowser(); virtual void fileClose(); virtual void fileExit(); - virtual void closeEvent( QCloseEvent * ); virtual void addRecord(); virtual void deleteRecord(); virtual void updateTableView( int lineToSelect );