QQmlApplicationEngine::quit and QGuiApplication::quit



  • 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?


  • Lifetime Qt Champion

    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();
    }
    @



  • 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".


  • Lifetime Qt Champion

    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



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

    QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.