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