diff options
author | Simon Rettberg | 2023-01-20 11:21:56 +0100 |
---|---|---|
committer | Simon Rettberg | 2023-01-20 11:21:56 +0100 |
commit | ab0a11f177091855d9c6488ab999daeadc6e9b9c (patch) | |
tree | 199b7db441422394a4db04741514549158111665 | |
parent | Mdernize CMakeLists.txt build type handling (diff) | |
download | pvs2-ab0a11f177091855d9c6488ab999daeadc6e9b9c.tar.gz pvs2-ab0a11f177091855d9c6488ab999daeadc6e9b9c.tar.xz pvs2-ab0a11f177091855d9c6488ab999daeadc6e9b9c.zip |
[pvsmgr] Fix app-exit in --manager-only mode on Qt5.15
In newer Qt versions, calling QApplication::exit() in the
App constructor deadlocks the application. Set a flag
instead and exit from main()
-rw-r--r-- | src/server/main.cpp | 3 | ||||
-rw-r--r-- | src/server/serverapp/serverapp.cpp | 11 | ||||
-rw-r--r-- | src/server/serverapp/serverapp.h | 5 |
3 files changed, 11 insertions, 8 deletions
diff --git a/src/server/main.cpp b/src/server/main.cpp index d975f80..7ae0466 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -1,4 +1,3 @@ -#include "mainwindow/mainwindow.h" #include "serverapp/serverapp.h" #include <QDebug> @@ -21,6 +20,8 @@ void usage() int main(int argc, char** argv) { ServerApp app(argc, argv); + if (app.shouldExit()) + return 0; for (QString a : app.arguments()) { if (a == "--usage" || a == "--help") { diff --git a/src/server/serverapp/serverapp.cpp b/src/server/serverapp/serverapp.cpp index 933517b..900d3a4 100644 --- a/src/server/serverapp/serverapp.cpp +++ b/src/server/serverapp/serverapp.cpp @@ -1,11 +1,12 @@ +#include "../mainwindow/mainwindow.h" +#include "serverapp.h" +#include "../../shared/util.h" + #include <QTranslator> #include <QNetworkInterface> #include <QSettings> #include <QLibraryInfo> -#include "serverapp.h" -#include "../../shared/util.h" - static QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clientSize); ServerApp::ServerApp(int& argc, char** argv) @@ -21,8 +22,8 @@ ServerApp::ServerApp(int& argc, char** argv) // If started in manager-only mode, and there is no current room // after reading the config, exit right away - if (_managerOnly && _currentRoom == "") { - QApplication::exit(0); + if (_managerOnly && _currentRoom.isEmpty()) { + _doExit = true; return; } diff --git a/src/server/serverapp/serverapp.h b/src/server/serverapp/serverapp.h index b2b16c5..3cb40b5 100644 --- a/src/server/serverapp/serverapp.h +++ b/src/server/serverapp/serverapp.h @@ -1,8 +1,6 @@ #ifndef SERVERAPP_H #define SERVERAPP_H -#include "../mainwindow/mainwindow.h" - #include <QApplication> #include <QStringList> #include <QMap> @@ -49,6 +47,7 @@ private: QByteArray _sessionNameArray; QMap<QString, Room*> _rooms; QString _currentRoom; + bool _doExit{}; bool _managerOnly{}; bool _isExam{}; @@ -78,6 +77,8 @@ public: void setCurrentRoom(const QString& room) { _currentRoom = room; } void setExam(bool exam) { _isExam = exam; } + bool shouldExit() const { return _doExit; } + }; #endif |