quit Qt application, not working
-
Implemented quit operation using a push button, but it is not working.
this is the line used :
connect(hCloseButton, SIGNAL(clicked()), this, SLOT(quit()));
this line is used in side a widget.
is it to be modified?
Thanks in advance. -
@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()
? -
Hi
check the return from connect to see if its ok.
You tell is that "this" have a function quit()
is that true?
Maybe this should be application?Did you try just to call close() ?
edit: @JKSH was faster :)
-
-
@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()));
-
Hi
just include
#include <QApplication>
and its known.Or as @J-Hilk says if that is the case :)
Post 1 of 14