title: Qt - How to detect closed window in custom event loop without using slots
body: <p>I'm working on an OpenGL-based game using QGLWidget as a front-end. But due to all of the unnecessary overhead (plus having to distribute the heavy QT libraries!) I plan to migrate to GLUT, and am in the process of replacing 'Qt-stuff' with more standard alternatives before the big leap.</p>
  
  <p>To replace the QTimers that control the framerate and fps timer, I'm trying to wedge those functions into a simple loop that replaces the app.exec() call, as follows:</p>
  
  <pre><code>//main.cpp
  #include &lt;QApplication&gt;
  #include &lt;windows.h&gt;
  #include "mainwindow.h"
  
  int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    MainWindow mainWin;//only contains a glwidget
    mainWin.show();
  
    do {
      app.processEvents();
      //call draw functions/fps based on system tick count
      //...
      Sleep(10);
    } while (!app.closingDown()); //&lt;-- this doesn't terminate
  
    return 0;
  }
  </code></pre>
  
  <p>So far it works fine during runtime, however once you try to close the window (via the system 'X' button), the window goes away but the program hangs in the background.  The problem is that I can't find a static flag or query function that indicates that exit() or close() has been called.  <code>bool closingDown()</code> always seems to be false, and I've tried toggling a static flag in the <code>~MainWindow</code> destructor and detecting that, but that doesn't work either since that isn't called until <code>main</code> ends.  I know I could probably do it by tying into QApps' <code>aboutToQuit()</code> signal, or maybe making a derived class from Qapp, and intercepting it, but that kind of defeats the purpose of moving away from signals/slots.  Is there a simple way to tell if a QApplication has been ordered to shut down, from outside of the class?</p>