forked from qt-creator/qt-creator
		
	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>
This commit is contained in:
		| @@ -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(); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user