Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Catching unix interrupt signal on console application when debugging with QtCreator
Forum Update on Monday, May 27th 2025

Catching unix interrupt signal on console application when debugging with QtCreator

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Damien
    wrote on 21 Mar 2019, 09:02 last edited by
    #1

    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

    J 1 Reply Last reply 21 Mar 2019, 11:38
    0
    • D Damien
      21 Mar 2019, 09:02

      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

      J Offline
      J Offline
      JonB
      wrote on 21 Mar 2019, 11:38 last edited by JonB
      #2

      @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! :)

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Damien
        wrote on 22 Mar 2019, 10:46 last edited by
        #3

        @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

        1 Reply Last reply
        3

        3/3

        22 Mar 2019, 10:46

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved