Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQmlApplicationEngine::quit and QGuiApplication::quit

QQmlApplicationEngine::quit and QGuiApplication::quit

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tilsitt
    wrote on last edited by
    #1

    Hi,

    I found an issue with the following code:

    @
    MyApplication::MyApplication(int& _argc, char** _argv):
    QGuiApplication(_argc, _argv)
    {
    QQmlApplicationEngine *engine = new QQmlApplicationEngine(
    QUrl("qrc:/my.qml"),
    this
    );

    connect(
        engine, &QQmlApplicationEngine :: quit,
        this, &QGuiApplication :: quit
    );
    

    }
    @

    "Qt.quit()":http://qt-project.org/doc/qt-5/qml-qtqml-qt.html#quit-method is called in my QML, and I checked QQmlApplicationEngine::quit was effectively emitted, but the application doesn't quit. I ended up with the following workaround:

    @
    connect(
    engine, &QQmlApplicationEngine :: quit,
    engine, &QQmlApplicationEngine :: deleteLater
    );
    connect(
    engine, &QQmlApplicationEngine :: destroyed,
    this, &QGuiApplication :: quit
    );
    @

    This version is working: QQmlApplicationEngine::quit schedules engine's deletion which exits the application. It seems QGuiApplication::quit doesn't work if the application has an alive QQmlApplicationEngine child. Did anybody experience something like that?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What happens if you have something like

      @
      int main(int argc, char *argv[])
      {
      QGuiApplication app(argc, argv);
      QQmlApplicationEngine engine(QUrl("qrc:/my.qml"));
      connect(engine, &QQmlApplicationEngine :: quit,
      &app, &QGuiApplication :: quit);

      return app.exec();
      }
      @

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      PhrogzP 1 Reply Last reply
      1
      • T Offline
        T Offline
        tilsitt
        wrote on last edited by
        #3

        Yes, it's working. I tried your version while using again the application as parent for the QML engine: the application became persistent again, so it's really to link the objects that seems to be the source of this "bug".

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I can't tell if it's a bug, untested scenario or expected behavior. You should have a look at the "bug report system":http://bugreports.qt-project.org to see if someone already wrote about that

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            What happens if you have something like

            @
            int main(int argc, char *argv[])
            {
            QGuiApplication app(argc, argv);
            QQmlApplicationEngine engine(QUrl("qrc:/my.qml"));
            connect(engine, &QQmlApplicationEngine :: quit,
            &app, &QGuiApplication :: quit);

            return app.exec();
            }
            @

            PhrogzP Offline
            PhrogzP Offline
            Phrogz
            wrote on last edited by
            #5

            Under Qt 5.9 I had to modify the connect() call by @SGaist to:

            QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit);
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved