Nominate our 2022 Qt Champions!

Catching unix interrupt signal on console application when debugging with QtCreator

  • 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)
        exit_flag = 1;
    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?


  • @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 say F5 is doing. Have a look at to see if the setting mentioned there helps you? Or don't press F5! :)

  • @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.


Log in to reply