diff options
Diffstat (limited to 'tools/qml/main.cpp')
-rw-r--r-- | tools/qml/main.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index a795144984..d718067616 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -160,18 +160,23 @@ public: LoadWatcher(QQmlApplicationEngine *e, int expected) : QObject(e) , earlyExit(false) + , returnCode(0) , expect(expected) , haveOne(false) { connect(e, SIGNAL(objectCreated(QObject*,QUrl)), this, SLOT(checkFinished(QObject*))); // QQmlApplicationEngine also connects quit() to QCoreApplication::quit - // but if called before exec() then QCoreApplication::quit does nothing + // and exit() to QCoreApplication::exit but if called before exec() + // then QCoreApplication::quit or QCoreApplication::exit does nothing connect(e, SIGNAL(quit()), this, SLOT(quit())); + connect(e, &QQmlEngine::exit, + this, &LoadWatcher::exit); } bool earlyExit; + int returnCode; private: void contain(QObject *o, const QUrl &containPath); @@ -196,14 +201,20 @@ public Q_SLOTS: if (! --expect) { printf("qml: Did not load any objects, exiting.\n"); - exit(2);//Different return code from qFatal + std::exit(2);//Different return code from qFatal } } void quit() { //Will be checked before calling exec() earlyExit = true; + returnCode = 0; } + void exit(int retCode) { + earlyExit = true; + returnCode = retCode; + } + #if defined(QT_GUI_LIB) && !defined(QT_NO_OPENGL) void onOpenGlContextCreated(QOpenGLContext *context); #endif @@ -582,7 +593,7 @@ int main(int argc, char *argv[]) } if (lw->earlyExit) - return 0; + return lw->returnCode; return app->exec(); } |