diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b7f04b269..b6282a69b 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -359,6 +359,22 @@ void MainWindow::UncheckAll() ToggleAllChecked(false); } +void MainWindow::closeEvent(QCloseEvent *event) +{ + // Check that we aren't checking files + if (!mThread.IsChecking()) + event->accept(); + else + { + QString msg(tr("Cannot exit while checking.\n\n" \ + "Stop the checking before exiting.")); + QMessageBox *box = new QMessageBox(QMessageBox::Warning, + tr("cppcheck"), msg); + box->show(); + event->ignore(); + } +} + void MainWindow::ToggleAllChecked(bool checked) { mActionShowAll.setChecked(checked); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 6c1b5572b..d79e66eb1 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -141,6 +141,11 @@ protected slots: void ResultsAdded(); protected: + /** + * @brief Event coming when application is about to close. + */ + virtual void closeEvent(QCloseEvent *event); + /** * @brief Helper function to toggle all show error menu items * @param checked Should all errors be shown (true) or hidden (false) diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index c7a5a271c..37df356b0 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -71,6 +71,11 @@ void ThreadHandler::Check(Settings settings, bool recheck) } } +bool ThreadHandler::IsChecking() const +{ + return mRunningThreadCount > 0; +} + void ThreadHandler::SetThreadCount(const int count) { if (mRunningThreadCount > 0 || diff --git a/gui/threadhandler.h b/gui/threadhandler.h index 21bb8d93b..25de349aa 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -85,6 +85,12 @@ public: */ void Check(Settings settings, bool recheck); + /** + * @brief Is checking running? + * + * @return true if check is running, false otherwise. + */ + bool IsChecking() const; signals: /**