aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qml
diff options
context:
space:
mode:
authorAlan Alpert <416365416c@gmail.com>2015-03-10 22:25:14 -0700
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2015-03-31 17:59:26 +0000
commitb252c2d479523c5f584d1754c4f5c5744a15f6fc (patch)
treeeae10e245556e26b2c57f7ae973b4651294b1990 /tools/qml
parent96a6cfe888d686e3377e219761fe29adcf5f71c2 (diff)
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 <kevin.krammer@kdab.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tools/qml')
-rw-r--r--tools/qml/main.cpp18
1 files changed, 17 insertions, 1 deletions
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 <QFileInfo>
#include <QRegularExpression>
#include <QStringList>
+#include <QScopedPointer>
#include <QDebug>
#include <QStandardPaths>
#include <QTranslator>
@@ -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<LoadWatcher> 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();
}