From b252c2d479523c5f584d1754c4f5c5744a15f6fc Mon Sep 17 00:00:00 2001 From: Alan Alpert <416365416c@gmail.com> Date: Tue, 10 Mar 2015 22:25:14 -0700 Subject: qml tool should exit on Qt.quit() In a QML/C++ application there may be additional code after app.exec(). In a pure QML application this is not the case, and you may wish to call Qt.quit() during scene creation (before app.exec()). [ChangeLog][QtQml][qml] qml tool now quits immediately if Qt.quit() is called before all scenes complete creation. Change-Id: I5c6fb64769724350ef3d74c34e2ede2d06562e4b Reviewed-by: Kevin Krammer Reviewed-by: Shawn Rutledge --- tools/qml/main.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tools/qml/main.cpp') diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 070eee5c44..ea601ba946 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -172,13 +173,20 @@ class LoadWatcher : public QObject public: LoadWatcher(QQmlApplicationEngine *e, int expected) : QObject(e) + , earlyExit(false) , 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 + connect(e, SIGNAL(quit()), + this, SLOT(quit())); } + bool earlyExit; + private: int expect; bool haveOne; @@ -201,6 +209,11 @@ public Q_SLOTS: exit(2);//Different return code from qFatal } } + + void quit() { + //Will be checked before calling exec() + earlyExit = true; + } }; void quietMessageHandler(QtMsgType type, const QMessageLogContext &ctxt, const QString &msg) @@ -483,7 +496,7 @@ int main(int argc, char *argv[]) loadConf(confFile, !verboseMode); //Load files - LoadWatcher lw(&e, files.count()); + QScopedPointer lw(new LoadWatcher(&e, files.count())); // Load dummy data before loading QML-files if (!dummyDir.isEmpty() && QFileInfo (dummyDir).isDir()) @@ -515,6 +528,9 @@ int main(int argc, char *argv[]) } } + if (lw->earlyExit) + return 0; + return app->exec(); } -- cgit v1.2.3