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

[Reg 5.15 -> 6.x] Re-initializing QGuiApplication causes QQmlApplicationEngine to crash

    XMLWordPrintable

Details

    • Windows
    • ffb9dee1b0 (qt/qtbase/dev) ffb9dee1b0 (qt/tqtc-qtbase/dev) 7b7c9c6996 (qt/qtbase/6.4) 7b7c9c6996 (qt/tqtc-qtbase/6.4) 7b7c9c6996 (qt/tqtc-qtbase/6.4.1) 7b7c9c6996 (qt/tqtc-qtbase/tqtc/qtinsight-6.4), ec5370458 (6.4), 9d36ae3f8 (dev), fbbf6f35c (dev)

    Description

      Steps to reproduce

      Run the attached project and close the window each time it appears.

       

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      int main()
      {
          for (int i = 1; i <= 3; ++i)
          {
              qDebug() << "Launching Qt app, repetition" << i;
      
              int argc = 1;
              QByteArray argv0("Window");
              QVector<char*> argv{argv0.data()};
      
              QGuiApplication app(argc, argv.data());
              QQmlApplicationEngine engine;
      
              qDebug("About to load main.qml...");
              engine.load(QUrl("qrc:/main.qml"));
              qDebug("...main.qml loaded");
      
              app.exec();
              qDebug("Window closed");
          }
      }
      

       

      Result

      Qt 6.3.0:

      Launching Qt app, repetition 1
       About to load main.qml...
       ...main.qml loaded
       Window closed
       Launching Qt app, repetition 2
       About to load main.qml...
       11:45:27: D:\Test\build-ReloadableApp-Desktop_Qt_6_3_0_MSVC2019_64bit-Debug\debug\ReloadableApp.exe crashed.

       

      Qt 5.15.2:

      Launching Qt app, repetition 1
      About to load main.qml...
      ...main.qml loaded
      Window closed
      Launching Qt app, repetition 2
      About to load main.qml...
      ...main.qml loaded
      Window closed
      Launching Qt app, repetition 3
      About to load main.qml...
      ...main.qml loaded
      Window closed

       

      Use-case

      Unloading and reloading QApplication is typically done when Qt is used to implement a plugin for a larger non-Qt application

       

      Notes

      • The crash does not occur if the QGuiApplication constructor is moved outside the for-loop (so it is never destroyed in the loop). However, this is not always feasible.
      • QWidget-based GUIs do not crash.

      Attachments

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

        Activity

          People

            owolff Oliver Wolff
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: