title: create qt thread event loop
body: <p>I am using Qt in order to write a GUI application.</p>
  
  <p>A main thread is responsible for the GUI and creates an QThread in order to do some work with an object.</p>
  
  <pre><code>class Worker
  {
      void start() {
          QTimer* timer = new Timer();
          connect(timer,SIGNAL(timeout()),this,SLOT(do()));
      }
  
      void do() {
          //do some stuff
          emit finished();
      }
  }
  
  
  
  class GUI
  {
      //do some GUI work then call startWorker();
  
      void startWorker() {
          QThread* thread = new Thread();
          Worker* worker = new Worker();
  
          worker-&gt;moveToThread(thread);
  
          connect(thread, SIGNAL(started()), worker, SLOT(start()));
          connect(worker, SIGNAL(finished()), workerthread, SLOT(quit()));
          connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
      }
  }
  </code></pre>
  
  <p>Now I have several problems:</p>
  
  <ol>
  <li><p>The timer in my worker class does not work. Maybe it is because the <a href="https://stackoverflow.com/questions/3374034/qtimer-in-a-thread-events-not-processing">new thread has no event loop</a>, but I have no idea how to create such one. I tried </p>
  
  <p><code>connect(workerthread, SIGNAL(started()), workerthread, SLOT(exec()));</code></p>
  
  <p>but it does not work either.</p></li>
  <li><p>When I try to wait on the new thread, the signal is never sent</p>
  
  <pre><code>class GUI
  {
      void exit() {
          thread-&gt;wait();
      }
  }
  </code></pre></li>
  </ol>
  
  <p>I think it also is because there is no event loop and because of that no signal is emitted.</p>
  
  <p>Does anybody have an idea how to solve these problems?</p>