.
When you close your app using CTRL+C, your app.exec() method doesn't return. Your app is killed by an unix signal called "SIGINT":.
If you're looking for last second clean-up, you should use "QCoreApplication::aboutToQuit": signal
Ah, I'm talking about Linux... I'm not sure how windows implements those stuffs.":. There is an interesting thread about it on "stackoverflow":.
I think the thread title doesn't correspond thread's topic. This is confusing.
chk if "this faq": helps, and if you can take a similar approach to handle CTRL+C
aboutToQuit() won't help, as was previously posted, and neither will qAddPostRoutine(). Look up the man page for the signal() system function to catch SIGKILL (which is what Ctrl-C sends).
kalle: Ctrl-C does send SIGTERM, not SIGKILL.
You can not catch SIGKILL, that one will always kill the application (and is what if send via the command "kill -9 <PID>").
[quote author="Tobias Hunger" date="1287045094"]kalle: Ctrl-C does send SIGTERM, not SIGKILL.
You can not catch SIGKILL, that one will always kill the application (and is what if send via the command "kill -9 <PID>").[/quote]
Afaik no.
SIGTERM is the default signal sent by kill (without -9)
SIGINT is the signal sent by terminal when you press ctrl-c.
"":
"":
[edit: fixed link / chetankjain]
danilocesar: You are right. I am getting old and start mixing up things:-(.
@Tobias: What do you think about this:
QCoreApplication could automatically catch SIGTERM and SIGINT (and relatives for windows/mac/symbian/whatever) and return pre-defined values for the exec() method.
I don't know if it's portable, but it can be useful...
.??]
I prefer to use signal management, such as
@
#include <signal.h>
static void m_cleanup(int sig)
{
qDebug() << "Bye :)";
// your destructor stuff
if (m_obj) delete m_obj; m_obj = NULL;
if (sig == SIGINT) qApp->quit();
}
int main(int argc, char *argv[])
{
...
signal(SIGINT, m_cleanup);
...
}
@