title: Windows console application - Is it possible to detect (and handle) the window close (X) button hit?
body: <p><em>I don't want to deflect the button hit or ignore the close event. I just need to run some cleanup code.</em></p>
  <p>Let me tell you what I've tried so far:</p>
  <p><em><strong>atexit()</strong></em></p>
  <p><em><strong>_onexit()</strong></em></p>
  <p><em><strong>SetConsoleCtrlHandler()</strong></em></p>
  <p><em><strong>~QCoreApplication()</strong></em></p>
  <p>No code set by these is being executed.
  The process just get killed when I press the X.</p>
  <p>I certainly can make a windowed app and solve this, but is there a solution for a console application?</p>
  <p>Thanks!</p>