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 Updated to NodeBB v4.3 + New Features

Catching unix interrupt signal on console application when debugging with QtCreator

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 4.7k 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 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

    JonBJ 1 Reply Last reply
    0
    • D 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,
      -Damien

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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 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

        • Login

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