Solved Connecting quit signal in main.cpp for Qt.quit()
-
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 thereturn
: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 mymain
so that I can callQt.quit()
from QML? -
@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 ;-)
-
@J.Hilk That solved it. Thank you!