Qt Error: Signal QDeclarativeEngine::quit() emitted, but no receivers connected to handle it

c++, qml, qt

Solution

The syntax is:

connect(sender, SIGNAL(signalName(args)), receiver, SLOT(slotName(args)));

You can put it in your MyClass constructor:

connect(this, SIGNAL(quit()), qApp, SLOT(quit()));

Or in the main function, since `connect()` is a static function, as Slavic81 pointed out in the comment below.

Note that qApp is a macro for the global application.

Problem

I am very new to Qt so that some Qt issues I can't figure out. I will really appreciate if somebody can help me. I am trying to get rid of application window's frame and create an exit button in qml in order to exit the application. Hence, I make a program as following: main.cpp ``` #include <QtGui/QApplication> #include <QDeclarativeContext> #include <QObject> #include "qmlapplicationviewer.h" #include "myclass.h" #include "mainwindow.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QApplication app(argc, argv); MyClass myClass; MainWindow window; window.rootContext()->setContextProperty("myObject", &myClass); window.show(); return app.exec(); } ``` mainwindow.cpp ``` #include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QDeclarativeView(parent) { // No window decorations setWindowFlags(Qt::FramelessWindowHint); // Set QML file setSource(QUrl::fromLocalFile("qml/Test2/main.qml")); } // Destructor. MainWindow::~MainWindow() { } ``` myclass.cpp ``` #include <QDeclarativeEngine> #include <QDeclarativeComponent> #include <QDeclarativeContext> #include <stdio.h> #include "myclass.h" MyClass::MyClass() { click_count = 0; } int MyClass::click_function(void) { click_count++; fprintf(stderr, "CLICK COUNT in CPP: %d\n", click_count); return click_count; } ``` qml ``` MouseArea { id: mouse_exit anchors.fill: parent onClicked: { console.log("Click on exit button: ") console.log("click count: ", myObject.click_function()) Qt.quit(); } } ``` It compiles successfully, however, whenever I click on the exit button, the Qt error "Signal QDeclarativeEngine::quit() emitted, but no receivers connected to handle it" occurs. Based on my searching online for this issue, it seems like I have to connect the QDeclarativeEngine::quit() signal to the QApplication::quit() slot. But there isn't too much information for using connect() function. I tried many ways to use connect(), but I still couldn't know how to use it for this case. Can anybody help me solve this problem? I will really really appreciate!

Original source