I have a QObject subclass that does some heavy processing—let's call it Processor. It reads in data from a file (or two), does stuff to the data, then writes a new file. I would like to move Processor to another thread so that my main application can continue operation while it processes. To me this sounds like a classic use of QThread.

However, when I try QObject::moveToThread(), the program throws an exception and I can't figure out what I'm doing wrong. I'm trying to follow the concepts set forth here: http://labs.qt.nokia.com/2010/06/17/...oing-it-wrong/

Here's a version of my code. Processor* "proc" and QThread* processingThread are private class members of MainWindow.

Qt Code:
  1. processingThread = new QThread;
  2. proc = new Processor(/*send stuff to the constructor*/); //nothing is passed to the QObject constructor, so it should have no parent
  3. proc->moveToThread(processingThread); //exception here at QCoreApplication::notifyInternal(QObject*,QEvent*)
  4. //connect signals and slots between the processor and a QProgressDialog "pdia"
  5.  
  6. /* start processing */
  7. processingThreadstart();
  8. QTimer::singleShot(0, proc, SLOT(beginProcessing()));
  9. pdia->exec();
To copy to clipboard, switch view to plain text mode