From cc9e5c3816b7743602245e876e73b92f6618b79b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 15 Jan 2019 13:13:45 +0100 Subject: [PATCH] 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 Reviewed-by: Tim Jenssen --- .../wizards/projects/qtquickapplication/main.cpp | 10 +++++++--- 1 file 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 986dcd606f1..70ae0ef96ce 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(); }