diff --git a/src/gui/src/QBarrierApplication.cpp b/src/gui/src/QBarrierApplication.cpp index f9362c74..7a6ec970 100644 --- a/src/gui/src/QBarrierApplication.cpp +++ b/src/gui/src/QBarrierApplication.cpp @@ -29,6 +29,12 @@ QBarrierApplication::QBarrierApplication(int& argc, char** argv) : m_Translator(NULL) { s_Instance = this; + + // By default do not quit when the last window is closed as we minimise + // to the system tray, but listen for the lastWindow closing so that + // if the system tray is not available we can quit. + setQuitOnLastWindowClosed(false); + connect(this, &QApplication::lastWindowClosed, this, &QBarrierApplication::onLastWindowClosed); } QBarrierApplication::~QBarrierApplication() @@ -69,3 +75,12 @@ void QBarrierApplication::setTranslator(QTranslator* translator) m_Translator = translator; installTranslator(m_Translator); } + +void QBarrierApplication::onLastWindowClosed() +{ + // If there is no system tray available then quit when the last window is closed + if (!QSystemTrayIcon::isSystemTrayAvailable()) + { + quit(); + } +} diff --git a/src/gui/src/QBarrierApplication.h b/src/gui/src/QBarrierApplication.h index 1b06ba08..03c941c9 100644 --- a/src/gui/src/QBarrierApplication.h +++ b/src/gui/src/QBarrierApplication.h @@ -37,6 +37,9 @@ class QBarrierApplication : public QApplication static QBarrierApplication* getInstance(); + private Q_SLOTS: + void onLastWindowClosed(); + private: QTranslator* m_Translator; diff --git a/src/gui/src/main.cpp b/src/gui/src/main.cpp index 5bf5898c..729e4837 100644 --- a/src/gui/src/main.cpp +++ b/src/gui/src/main.cpp @@ -88,8 +88,6 @@ int main(int argc, char* argv[]) } #endif - QApplication::setQuitOnLastWindowClosed(false); - QSettings settings; AppConfig appConfig (&settings);