quit Qt application, not working
-
@o6a6r9v1p said in quit Qt application, not working:
connect(hCloseButton, SIGNAL(clicked()), this, SLOT(quit()));
What is
this
?Are your trying to activate
QCoreApplication::quit()
? -
@o6a6r9v1p
Ok but the user class should then connect to Application instance
so it would be
qDebug() << "quit conn:" << connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));and check it says
quit conn: true -
just use
hCloseButton
instead :)
the ui->butt was just from my sample to see that it did close.You did read docs about connect ?
http://doc.qt.io/qt-5/signalsandslots.htmlThis is a MUST read if you are to use Qt.
-
I have this main function
@int main (int argc, char* argv[])
{QApplication app(argc, argv);
// setLayout(verticalLayout);
// window.setWindowTitle(QApplication::translate("Device Monitor"));myApp w;
// w.show();
return app.exec();
}
@myApp is user class, in this "CLOSE" button is created. we want to use it , instead of using "X" in GUI to close the application.
we didnot use QT creator to generate GUI, we wrote it.this is where difference comes between my code and examples & ideas given in the forum.
-
Hi
Actually the X close the window
QApplication is set to exit exec()
when last top window is closedIt dont matter if u used UI file or programmed it.
But the shown connect
qDebug() << "quit conn:" << connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));will not close window but try to make whole app quit.
-
-
@mrjj
i did as you told, I got the following- when i used
@
connect(hCloseButton, SIGNAL(clicked()), this, SLOT(quit()));
@
it gave the message
"QObject::connect: No such slot myApp::quit()"it compiles with no errors.
When Pushbutton is pressed it does not close the Application.- when i used
@
connect(hCloseButton, SIGNAL(clicked()), qApp, SLOT(quit()));
@
it did not compile.
it gave the error message
"qApp was not declared in this scope"
- when i used
-
qApp is a global pointer referring to the unique application object. It is equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, so only valid when the unique application object is a QApplication.
-> your main does not have a QApplication object
You said, you have no UI for the designer so I Asume you have a
QCoreApplication
in your main.and try the following in it
//create a `myApp::quit()` QCoreApplication::quit();
or
connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));