Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
5.3.0
-
None
Description
QQmlApplicationEngine should exit the application if the root item cannot be loaded (e.g. because the file is not found, our has syntax errors). So far the application will run (maybe printing the error), but not exit.
This is the advocated use of QQmlApplicationEngine:
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine("main.qml"); return app.exec(); }
If main.qml has errors, app.exec() will run, but no windows will show up. A workaround might be:
QQmlApplicationEngine engine("main.qml"); if (engine.rootObjects().isEmpty()) return 1;
But it's not obvious to me whether it's guaranteed that the rootObjects are already created after the constructor call?
Anyhow, I'd argue that failing to load the root component is always a fatal condition, and should be considered a programming error that is best handled by exit. Applications that for one reason or the other do want to handle this on their own are free to use QQmlEngine/QQmlComponent directly.
Attachments
Issue Links
- relates to
-
QTBUG-39469 Starting a Qt Quick App with syntax errors creates invisible background process
- Closed