Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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)
    {
        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



  • @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 https://stackoverflow.com/questions/19409573/qt-creator-stops-on-linux-signal 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.

    0_1553251374689_c65043a0-8bce-44de-b7ac-d4abad4e695e-image.png


Log in to reply