Catching unix interrupt signal on console application when debugging with QtCreator
-
wrote on 21 Mar 2019, 09:02 last edited by
Hi,
I have a console application which in a very stripped version looks like this:
#include <QCoreApplication> #include <QDebug> static int exit_flag = 0; static void sigexit(int sig) { Q_UNUSED(sig); exit_flag = 1; QCoreApplication::exit(exit_flag); } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); int error = 0; qDebug() << "Application started"; // Do something interresting... signal(SIGTERM, sigexit); // catch kill signal signal(SIGHUP, sigexit); // catch hang up signal signal(SIGQUIT, sigexit); // catch quit signal signal(SIGINT, sigexit); // catch a CTRL-c signal error = a.exec(); // Do some cleanup ... qDebug() << "Application will exit now"; return error; }
If I run the application directly in console, I'm able to interrupt the process and the application closes down gracefully.
Meanwhile, if I debug the application in QtCreator and type CTRL-c, the debugger breaks in qeventdispatcher_glib.cpp QEventDispatcherGlib::processEvents. If I press F5 to continue, the application keeps running and never exits.
Any ideas how I could fix that?
Thanks,
-Damien -
Hi,
I have a console application which in a very stripped version looks like this:
#include <QCoreApplication> #include <QDebug> static int exit_flag = 0; static void sigexit(int sig) { Q_UNUSED(sig); exit_flag = 1; QCoreApplication::exit(exit_flag); } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); int error = 0; qDebug() << "Application started"; // Do something interresting... signal(SIGTERM, sigexit); // catch kill signal signal(SIGHUP, sigexit); // catch hang up signal signal(SIGQUIT, sigexit); // catch quit signal signal(SIGINT, sigexit); // catch a CTRL-c signal error = a.exec(); // Do some cleanup ... qDebug() << "Application will exit now"; return error; }
If I run the application directly in console, I'm able to interrupt the process and the application closes down gracefully.
Meanwhile, if I debug the application in QtCreator and type CTRL-c, the debugger breaks in qeventdispatcher_glib.cpp QEventDispatcherGlib::processEvents. If I press F5 to continue, the application keeps running and never exits.
Any ideas how I could fix that?
Thanks,
-Damienwrote on 21 Mar 2019, 11:38 last edited by JonB@Damien
Qt Creator (I don't use it, so don't ask me for more information!) is trapping this for you to be helpful :) IIRC,gdb
stops on a signal and then you can either proceed re-raising the signal or ignoring the signal, which sounds a bit like what you sayF5
is doing. Have a look at https://stackoverflow.com/questions/19409573/qt-creator-stops-on-linux-signal to see if the setting mentioned there helps you? Or don't pressF5
! :) -
wrote on 22 Mar 2019, 10:46 last edited by
@JonB said in Catching unix interrupt signal on console application when debugging with QtCreator:
s a bit like what you say F5 is doin
Thanks @JonB.
I got around the issue by adding pass nonstop noprint configuration for the required signals in Tools > Options > Debugger > Locals & Expression > Debugging Helper Customization.
3/3