title: Starting QTimer In A QThread
body: <p>I am trying to start a QTimer in a specific thread. However, the timer does not seem to execute and nothing is printing out. Is it something to do with the timer, the slot or the thread?</p>
  
  <p>main.cpp</p>
  
  <pre><code>    #include "MyThread.h"
      #include &lt;iostream&gt;
      using namespace std;
  
      int main(int argc, char *argv[]) {
          MyThread t;
          t.start();
          while(1);
      }
  </code></pre>
  
  <p>MyThread.h</p>
  
  <pre><code>    #ifndef MYTHREAD_H
      #define MYTHREAD_H
  
      #include &lt;QTimer&gt;
      #include &lt;QThread&gt;
      #include &lt;iostream&gt;
  
      class MyThread : public QThread {
          Q_OBJECT
      public:
          MyThread();
      public slots:
          void doIt();
      protected:
          void run();
      };
  
      #endif  /* MYTHREAD_H */
  </code></pre>
  
  <p>MyThread.cpp</p>
  
  <pre><code>    #include "MyThread.h"
  
      using namespace std;
  
      MyThread::MyThread() {
          moveToThread(this);
      }
  
      void MyThread::run() {
          QTimer* timer = new QTimer(this);
          timer-&gt;setInterval(1);
          timer-&gt;connect(timer, SIGNAL(timeout()), this, SLOT(doIt()));
          timer-&gt;start();
      }
  
      void MyThread::doIt(){
          cout &lt;&lt; "it works";
      }
  </code></pre>