diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index b7b8a8ea3a..53dec5681e 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1457,9 +1457,10 @@ namespace Gui { */ class GUIApplication : public GUIApplicationNativeEventAware { + int systemExit; public: - GUIApplication(int & argc, char ** argv) - : GUIApplicationNativeEventAware(argc, argv) + GUIApplication(int & argc, char ** argv, int exitcode) + : GUIApplicationNativeEventAware(argc, argv), systemExit(exitcode) { } @@ -1480,6 +1481,10 @@ public: else return QApplication::notify(receiver, event); } + catch (const Base::SystemExitException&) { + qApp->exit(systemExit); + return true; + } catch (const Base::Exception& e) { Base::Console().Error("Unhandled Base::Exception caught in GUIApplication::notify.\n" "The error message is: %s\n", e.what()); @@ -1543,7 +1548,8 @@ void Application::runApplication(void) Base::Console().Log("Init: Creating Gui::Application and QApplication\n"); // if application not yet created by the splasher int argc = App::Application::GetARGC(); - GUIApplication mainApp(argc, App::Application::GetARGV()); + int systemExit = 1000; + GUIApplication mainApp(argc, App::Application::GetARGV(), systemExit); // set application icon and window title const std::map& cfg = App::Application::Config(); std::map::const_iterator it; @@ -1716,9 +1722,15 @@ void Application::runApplication(void) Base::Console().Log("Init: Entering event loop\n"); try { - mainApp.exec(); + int ret = mainApp.exec(); + if (ret == systemExit) + throw Base::SystemExitException(); } - catch(...) { + catch (const Base::SystemExitException&) { + Base::Console().Message("System exit\n"); + throw; + } + catch (...) { // catching nasty stuff coming out of the event loop App::Application::destructObserver(); Base::Console().Error("Event loop left through unhandled exception\n"); diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 40fdb95577..f66adf95ef 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -281,6 +281,9 @@ void Command::invoke(int i) if (isActive()) activated( i ); } + catch (const Base::SystemExitException&) { + throw; + } catch (Base::PyException &e) { e.ReportException(); Base::Console().Error("Stack Trace: %s\n",e.getStackTrace().c_str()); diff --git a/src/Gui/Macro.cpp b/src/Gui/Macro.cpp index 1ac7964781..20a7f49c43 100644 --- a/src/Gui/Macro.cpp +++ b/src/Gui/Macro.cpp @@ -233,7 +233,7 @@ void MacroManager::run(MacroType eType,const char *sName) Base::Interpreter().runFile(sName, this->localEnv); } catch (const Base::SystemExitException&) { - qApp->quit(); + throw; } catch (const Base::PyException& e) { Base::Console().Error("%s%s: %s\n", diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index a13a16c2ca..cccdf146b4 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1157,8 +1157,7 @@ void MainWindow::delayedStartup() App::Application::processCmdLineFiles(); } catch (const Base::SystemExitException&) { - QApplication::quit(); - return; + throw; } const std::map& cfg = App::Application::Config(); diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index 780789b71d..eaa7f53cb4 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -709,7 +709,7 @@ void PythonConsole::runSource(const QString& line) } if (ret == QMessageBox::Yes) { PyErr_Clear(); - qApp->quit(); + throw; } else { PyErr_Clear(); diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp index 5552bd6b4d..288bc3df24 100644 --- a/src/Main/MainGui.cpp +++ b/src/Main/MainGui.cpp @@ -300,6 +300,9 @@ int main( int argc, char ** argv ) else App::Application::runApplication(); } + catch (const Base::SystemExitException&) { + exit(0); + } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); } diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index 81c02dd8b3..04739a3516 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -114,7 +114,7 @@ BrowserView::BrowserView(QWidget* parent) connect(view, SIGNAL(loadProgress(int)), this, SLOT(onLoadProgress(int))); connect(view, SIGNAL(loadFinished(bool)), - this, SLOT(onLoadFinished())); + this, SLOT(onLoadFinished(bool))); connect(view, SIGNAL(linkClicked(const QUrl &)), this, SLOT(onLinkClicked(const QUrl &))); connect(view->page(), SIGNAL(downloadRequested(const QNetworkRequest &)), @@ -242,12 +242,14 @@ void BrowserView::onLoadProgress(int step) bar->setValue(step); } -void BrowserView::onLoadFinished() +void BrowserView::onLoadFinished(bool ok) { - QProgressBar* bar = Sequencer::instance()->getProgressBar(); - bar->setValue(100); - bar->hide(); - getMainWindow()->statusBar()->showMessage(QString()); + if (ok) { + QProgressBar* bar = Sequencer::instance()->getProgressBar(); + bar->setValue(100); + bar->hide(); + getMainWindow()->statusBar()->showMessage(QString()); + } isLoading = false; } diff --git a/src/Mod/Web/Gui/BrowserView.h b/src/Mod/Web/Gui/BrowserView.h index c32dfd6591..553ccd1604 100644 --- a/src/Mod/Web/Gui/BrowserView.h +++ b/src/Mod/Web/Gui/BrowserView.h @@ -92,10 +92,10 @@ public: protected Q_SLOTS: void onLoadStarted(); void onLoadProgress(int); - void onLoadFinished(); - void onLinkClicked ( const QUrl & url ) ; + void onLoadFinished(bool); + void onLinkClicked (const QUrl& url); bool chckHostAllowed(const QString& host); - void onDownloadRequested(const QNetworkRequest & request); + void onDownloadRequested(const QNetworkRequest& request); private: WebView* view;