title: QApplication: How to shutdown gracefully on Ctrl-C
body: <p>I have a <code>QApplication</code> that, depending on command line parameters, sometimes doesn't actually have a GUI window, but just runs without GUI. In this case, I want to shut it down gracefully if <kbd>CTRL</kbd>-<kbd>C</kbd> was hit. Basically my code looks like this:</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
      QApplication app(argc, argv);
  
      ... // parse command line options
  
      if (no_gui) {
          QObject::connect(&amp;app, SIGNAL(unixSignal(int)),
                           &amp;app, SLOT(quit()));
          app.watchUnixSignal(SIGINT, true);
          app.watchUnixSignal(SIGTERM, true);
      }
  
      ... 
  
      return app.exec();
  }
  </code></pre>
  
  <p>However, this does not work. <kbd>CTRL</kbd>-<kbd>C</kbd> seems to be caught (the application doesn't get killed), but it also doesn't exit. What am I missing?</p>