Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-39470

QQmlApplicationEngine should exit if root component fails to load

    XMLWordPrintable

Details

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              kkohne Kai Köhne
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes