title: QThread - Move class member to thread using moveToThread
body: <p>I'm starting with multithreading and have some troubles moving objects to a QThread. My Controller class instanciates the Worker, creates the necessary thread for the Worker and move the Worker to the new thread. Computation on the worker starts when the worker thread is started. The Worker class contains a Dummy object, which is used during the worker calculation (function <code>Dummy::doDummyStuff()</code>). Everything seems to work fine, except that <code>doDummyStuff()</code> seems to be executed in the main (controller) thread instead of the worker thread. Is this because the Worker object (and hence the Dummy object) was created first in the main thread ? Is there a way to move all class members of the Worker object in the worker thread ? </p>
  
  <p>Here is a code snippet : </p>
  
  <p>Controller.h</p>
  
  <pre><code>class Controller: public QObject
  {
      Q_OBJECT
  
  public:
      Controller(std::vector&lt;double&gt; _data, QString _fn);
      void startControl();
  
  private:
      QThread workerThread_;
      Worker worker_;
      PostProcessing postProc_;
  
  };
  </code></pre>
  
  <p>Controller.cpp</p>
  
  <pre><code>Controller::Controller(std::vector&lt;double&gt; _data, QString _fn): QObject(), workerThread_(), worker_(_data), postProc_()
  {
      QObject::connect(&amp;workerThread_, SIGNAL(started()), &amp;worker_, SLOT(doWork()));
      QObject::connect(&amp;worker_, SIGNAL(signalResultReady(double)), &amp;postProc_, SLOT(update(double)));
  }
  
  void Controller::startControl()
  {
      worker_.moveToThread(&amp;workerThread_);
      workerThread_.start();
  }
  </code></pre>
  
  <p>Worker.h</p>
  
  <pre><code>class Worker: public QObject
  {
      Q_OBJECT
  
  public:
      Worker(std::vector&lt;double&gt; _coord);
  
  signals:
      void signalResultReady(double);
  
  public slots:
      void doWork();
  
  private:
      double res_;
      std::vector&lt;double&gt; coord_;
      Dummy dummyCreatedInWorker_;
  };
  </code></pre>
  
  <p>Worker.cpp</p>
  
  <pre><code>Worker::Worker(std::vector&lt;double&gt; _coord): QObject(), res_(0), coord_(_coord), dummyCreatedInWorker_()
  {
  }
  
  void Worker::doWork()
  {
      qDebug() &lt;&lt; "Worker thread ID" &lt;&lt; this-&gt;thread();
      for(unsigned int ii = 0; ii &lt; coord_.size(); ii++)
      {
          res_ += coord_[ii];
          dummyCreatedInWorker_.doDummyStuff();
          emit signalResultReady(res_);
  
          /* ....*/
      }
  }
  </code></pre>
  
  <p>Dummy::doDummyStuff</p>
  
  <pre><code>void Dummy::doDummyStuff()
  {
      qDebug() &lt;&lt; "Doing dummy stuff from thread" &lt;&lt; this-&gt;thread();
      for(int ii = 0; ii &lt; 10; ii++)
      {
          res_ += ii;
      }
  }
  </code></pre>