title: Qt cleanup on exit?
body: <p>I have an application for which a cleanup code should be run regardless of the way how the process ended. For example, if the program is being closed by the OS due to a restart, the cleanup code should be executed. Or if CTRL+C is pressed, the cleanup code should be executed.</p>
  
  <p>I've found the <code>QCoreApplication::aboutToQuit</code> signal.</p>
  
  <p>The docs for the signal state:</p>
  
  <blockquote>
    <p>This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This
    may happen either after a call to quit() from inside the application
    or when the users shuts down the entire desktop session.</p>
    
    <p>The signal is particularly useful if your application has to do some
    last-second cleanup. Note that no user interaction is possible in this
    state.</p>
  </blockquote>
  
  <p>However after testing, I've noticed that the signal isn't emitted when CTRL-C is pressed. It also isn't emitted when terminated by <code>kill</code>. </p>
  
  <p>On what 'exit' events is the signal emitted?</p>
  
  <p><em>My current opinion is that <code>QCoreApplication::aboutToQuit</code> is useless for handling outside signals and that it is used for 'exiting from inside an app' kind of events (a user clicks the X button to close the window), but won't help you if you want to make sure a certain event is executed even on a segmentation fault or the process being externally killed.</em></p>