PDA

View Full Version : Closing QCoreApplication by clicking X on top right corner



jmsbc
1st February 2011, 02:08
Hi,

I have a console application that uses QCoreApplication, and it is executed using exec():


int main()
{
QCoreApplication qtApp(argc, argv);

MsDbServer server;
server.start();

return qtApp.exec();
}

I want to perform some code clean-up when a user clicks on the "X" button on the top right corner of the console application. How can I detect when this window gets closed in this way?

Thanks

Lykurg
1st February 2011, 06:22
What's about QCoreApplication::aboutToQuit()?

jmsbc
1st February 2011, 19:35
What's about QCoreApplication::aboutToQuit()?
I tried connecting that signal but the slot AboutToQuit() doesn't get called (breakpoint doesn't get hit):


int main(int argc, char *argv[])
{
QCoreApplication qtApp(argc, argv);
MsDbServer server;
QObject::connect(&qtApp, SIGNAL(aboutToQuit()), &server, SLOT(AboutToQuit()));
return qtApp.exec();
}

class MsDbServer : public QObject
{
Q_OBJECT

public slots:
void AboutToQuit();
}