From 0b463dadb9cd9ddd22d8a12f7b7ce85257317bda Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 17 Jul 2010 23:52:50 +0300 Subject: [PATCH] GUI: Close application cleanly when exiting while checking. Earlier commit allowed cppcheck to exit immediately while checking. This however leads crashes and error logs shown since the thread termination leaves things in inconsistent state. I thought cppcheck would close fast enough so these could be ignored. But apparently not. So this commits adds new bool mExiting for MainWindow and sets that to true when exiting while checking. When the checking is ready this attribute is checked and if it is true the application can now be cleanly exited. --- gui/mainwindow.cpp | 14 ++++++++++---- gui/mainwindow.h | 9 +++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 67821c720..9fc9eb338 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -47,7 +47,8 @@ MainWindow::MainWindow() : mApplications(new ApplicationList(this)), mTranslation(new TranslationHandler(this)), mLanguages(new QActionGroup(this)), - mLogView(NULL) + mLogView(NULL), + mExiting(false) { mUI.setupUi(this); mUI.mResults->Initialize(mSettings, mApplications); @@ -399,6 +400,12 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list) void MainWindow::CheckDone() { + if (mExiting) + { + close(); + return; + } + mUI.mResults->CheckingFinished(); EnableCheckButtons(true); mUI.mActionSettings->setEnabled(true); @@ -522,10 +529,9 @@ void MainWindow::closeEvent(QCloseEvent *event) // exiting it doesn't matter. mThread->Stop(); SaveSettings(); - event->accept(); + mExiting = true; } - else - event->ignore(); + event->ignore(); } } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index f37cc9b67..f49d6d3e5 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -343,6 +343,15 @@ protected: */ LogView *mLogView; +private: + + /** + * @brief Are we exiting the cppcheck? + * If this is true then the cppcheck is waiting for check threads to exit + * so that the application can be closed. + */ + bool mExiting; + }; /// @} #endif // MAINWINDOW_H