title: QApplication does not exit when main window closes
body: <p>I have a QMainWindow that is used to browse and view images with. These images are special medical images that are read using a wrapper that I wrote.</p>
  
  <p>The GUI has a QListview on the left, which shows a list of thumbnails. When the user selects one of them, the QVTKWidget displays the corresponding image on the right. I use a vtkRenderWindowInteractor to manipulate the displayed image.</p>
  
  <p>My main looks like the following:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include "GUIClassName.h" //inherits from QMainWindow
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv); 
      GUIClassName w;
      w.show();
      return a.exec();
  }
  </code></pre>
  
  <p>My closeEvent looks like the following:</p>
  
  <pre><code>void GUIClassName::closeEvent(QCloseEvent* event)
  {
     // mainInteractor is a vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;    
     if (this-&gt;_mainInteractor != NULL) 
          this-&gt;_mainInteractor-&gt;TerminateApp();
      event-&gt;accept();
  }
  </code></pre>
  
  <p>The issue is that when I close the QMainWindow, the application does not terminate. That is the command prompt stays open and <i>Press any key to continue</i> does not appear. If I Ctrl+break, then the application exits (obviously) but I get the following message:</p>
  
  <blockquote>
    <p>QObject::~QObject: Timers cannot be stopped from another thread</p>
  </blockquote>
  
  <p>I have noticed that if I only select one thumbnail and display it in the QVTKWidget, the program terminates just fine. But when I select one thumbnail, display it and then select another thumbnail, then the program does not terminate when I close the window.</p>
  
  <p>I was wondering if anyone could tell me what I am doing wrong here. I would gladly copy/paste more code, but I am not sure which parts are relevant at the moment.</p>
  
  <p>I have read the following in hopes of an answer, but so far I have been unable to solve this issue: </p>
  
  <p><a href="https://stackoverflow.com/questions/8826747/qt-app-stays-in-memory-even-after-mainwindow-is-closed">Qt app stays in memory even after MainWindow is closed</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6303335/qt-process-stays-in-memory-after-application-closes?rq=1">Qt process stays in memory after application closes</a></p>
  
  <p><a href="https://stackoverflow.com/questions/26181486/c-application-does-not-kill-all-processes-on-exit?rq=1">C++ application does not kill all processes on exit</a></p>
  
  <p>Thanks</p>