diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-01-15 13:13:45 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-01-18 09:46:27 +0000 |
commit | cc9e5c3816b7743602245e876e73b92f6618b79b (patch) | |
tree | 036faefe8f1b3bd98d6ce9344d4ab937fed6e8c5 /share | |
parent | f007bc7593a4079ea7ce15d98df08c0cf8a1d5c9 (diff) |
Wizards: Handle errors more elegantly in Qt Quick application template
By monitoring the objectCreated() signal of QQmlApplicationEngine we can
also catch errors if the components are instantiated asynchronously.
Task-number: QTBUG-39469
Change-Id: I796eb5561fc8d48ab5aa74d37b0964b118a1ba7e
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'share')
-rw-r--r-- | share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp b/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp index 986dcd606f..70ae0ef96c 100644 --- a/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp +++ b/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp @@ -20,9 +20,13 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; + const QUrl url(QStringLiteral("qrc:/main.qml")); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, Qt::QueuedConnection); + engine.load(url); return app.exec(); } |