title: Exit QThread when GUI Application exits
body: <p>I have the following worker class:</p>
  
  <pre><code>class MediaWorker : public QObject
  {
      Q_OBJECT
  public:
      explicit MediaWorker(QObject *parent = 0);
      ~MediaWorker();
  
      void Exit();
  
  signals:
      void Finished();
  
  public slots:
      void OnExecuteProcess();
  };
  </code></pre>
  
  <p>In MediaWorker.cpp</p>
  
  <pre><code>void MediaWorker::Exit()
  {
      emit Finished();
  }
  
  void MediaWorker::OnExecuteProcess()
  {
      qDebug() &lt;&lt; "Worker Thread: " &lt;&lt; QThread::currentThreadId();
  }
  </code></pre>
  
  <p>In my MainWindow I do the following:</p>
  
  <pre><code>this-&gt;threadMediaWorker = new QThread();
  this-&gt;mediaWorker = new MediaWorker();
  this-&gt;timerMediaWorker = new QTimer();
  this-&gt;timerMediaWorker-&gt;setInterval(1000);
  
  this-&gt;timerMediaWorker-&gt;moveToThread(this-&gt;threadMediaWorker);
  this-&gt;mediaWorker-&gt;moveToThread(this-&gt;threadMediaWorker);
  
  connect(this-&gt;threadMediaWorker, SIGNAL(started()), this-&gt;timerMediaWorker, SLOT(start()));
  connect(this-&gt;timerMediaWorker, &amp;QTimer::timeout, this-&gt;mediaWorker, &amp;MediaWorker::OnExecuteProcess);
  
  connect(this-&gt;mediaWorker, &amp;MediaWorker::Finished, this-&gt;threadMediaWorker, &amp;QThread::quit);
  connect(this-&gt;mediaWorker, &amp;MediaWorker::Finished, this-&gt;mediaWorker, &amp;MediaWorker::deleteLater);
  connect(this-&gt;threadMediaWorker, &amp;QThread::finished, this-&gt;mediaWorker, &amp;QThread::deleteLater);
  
  this-&gt;threadMediaWorker-&gt;start();   
  </code></pre>
  
  <p>The threading is working properly.  When I close the application I terminate the thread in the destructor:</p>
  
  <pre><code>MainWindow::~MainWindow()
  {
      delete ui;
  
      this-&gt;mediaWorker-&gt;Exit();
  }
  </code></pre>
  
  <p>so Exit() emits the Finished signal which will hopefully delete the qthread and mediaworker class.  </p>
  
  <p>My question is if this is the proper way of terminating both the thread and media worker class?</p>