title: How do I process events on a QThread?
body: <p>Normally if I am in a process intensive function I can call <code>QCoreApplication::processEvents()</code> or <code>QEventLoop::processEvents()</code> to ensure that my processing doesn't block other signals and slots.</p>
  
  <p>However, if I create a new <code>QThread</code> and move a worker to that thread, then I don't have a <code>QCoreApplication</code> or a <code>QEventLoop</code> with which to call <code>processEvents()</code>.</p>
  
  <p>From my research, it seems that I should be able to install a <code>QEventLoop</code> on the new <code>QThread</code> I created, and then I can call <code>processEvents()</code> on that <code>QEventLoop</code>.</p>
  
  <p>However, I can't figure out how to do this. I figure it might look something like this:</p>
  
  <pre><code>QThread *thread = new QThread(this);
  Worker *worker = new Worker(this);
  QEventLoop *loop = new QEventLoop();
  
  connect(thread, SIGNAL(finished()), worker, SLOT(deleteLater()));
  connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
  connect(thread, SIGNAL(started()), worker, SLOT(startProcessing()));
  connect(worker, SIGNAL(done()), thread, SLOT(quit()));
  connect(worker, SIGNAL(done()), loop, SLOT(quit()));
  
  worker-&gt;moveToThread(thread);    
  
  //loop-&gt;exec() // blocks processing of this thread
  loop-&gt;moveToThread(thread);
  
  //loop-&gt;exec() // loop is not a member of this thread anymore and even
                 // if it was, this would block the thread from starting
  thread-&gt;start();
  //loop-&gt;exec(); // loop is not a member of this thread anymore and even
                  // if it was, this would block this thread from continuing
  </code></pre>
  
  <p>Every place I try to start the loop has some sort of issue. But even if something like this worked, how would I call <code>processEvents()</code> on that <code>QEventLoop()</code>?</p>
  
  <p>Alternatively, <code>QThread</code> also has a function <code>setEventDispatcher()</code> and <code>QAbstractEventDispatcher</code> has a <code>processEvents()</code> function, but I can't seem to find anything that subclasses <code>QAbstractEventDispatcher</code>.</p>
  
  <p>What is the proper way to process events during an intensive worker function on a <code>QThread</code>?</p>