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. Connecting quit signal in main.cpp for Qt.quit()
Qt 6.11 is out! See what's new in the release blog

Connecting quit signal in main.cpp for Qt.quit()

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 6.2k Views
  • 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.
  • PhrogzP Offline
    PhrogzP Offline
    Phrogz
    wrote on last edited by Phrogz
    #1

    I have an app shell written by others:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty()) return -1;
        return app.exec();
    }
    

    I want Qt.quit() to work in my application. Based on this forum answer from 2014 from @SGaist I added the following line before the return:

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

    This fails to compile with the error:

    main.cpp:9: error: no matching function for call to ‘QObject::connect(QQmlApplicationEngine&, void (QQmlEngine::*)(), QGuiApplication*, void (*)())’
    

    The combination of the heavily-overloaded connect() method and my general lack of Qt/C++ knowledge leaves me confused. Under Qt 5.9 how should I modify my main so that I can call Qt.quit() from QML?

    J.HilkJ 1 Reply Last reply
    0
    • PhrogzP Phrogz

      I have an app shell written by others:

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
          if (engine.rootObjects().isEmpty()) return -1;
          return app.exec();
      }
      

      I want Qt.quit() to work in my application. Based on this forum answer from 2014 from @SGaist I added the following line before the return:

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

      This fails to compile with the error:

      main.cpp:9: error: no matching function for call to ‘QObject::connect(QQmlApplicationEngine&, void (QQmlEngine::*)(), QGuiApplication*, void (*)())’
      

      The combination of the heavily-overloaded connect() method and my general lack of Qt/C++ knowledge leaves me confused. Under Qt 5.9 how should I modify my main so that I can call Qt.quit() from QML?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Phrogz said in Connecting quit signal in main.cpp for Qt.quit():

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

      I'm not fimilar with the issue, but just by looking at your connect statement, I see a typo:

      QObject::connect(engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit);
      // to ->
      QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit);
      

      Maybe that solves all issues ;-)


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      PhrogzP 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @Phrogz said in Connecting quit signal in main.cpp for Qt.quit():

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

        I'm not fimilar with the issue, but just by looking at your connect statement, I see a typo:

        QObject::connect(engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit);
        // to ->
        QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QGuiApplication::quit);
        

        Maybe that solves all issues ;-)

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

        @J.Hilk That solved it. Thank you!

        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