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>
This commit is contained in:
Alan Alpert 2015-03-10 22:25:14 -07:00 committed by Frederik Gladhorn
parent 96a6cfe888
commit b252c2d479
1 changed files with 17 additions and 1 deletions

View File

@ -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();
}