QML application wizards: Add code to bail out on load errors

When something goes wrong with deployment or there is a syntax
error in the QML files, the old code would enter the main
loop not showing any windows. Worse, the binary is then locked
on Windows and cannot be overwritten. Add a clause checking
whether there are any root objects and bail out on failure.

Task-number: QTBUG-60764
Change-Id: I3620a09ec4331dc04a5194dfd2ece2ff44bdc429
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Friedemann Kleint
2017-05-12 08:55:01 +02:00
parent 99ac955664
commit cf807253e4
3 changed files with 6 additions and 0 deletions

View File

@@ -6,6 +6,8 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec(); return app.exec();
} }

View File

@@ -10,6 +10,8 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec(); return app.exec();
} }

View File

@@ -11,6 +11,8 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml"))); engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec(); return app.exec();
} }