I haven't watched the youtube tutorial - so maybe the solution is already there, but this is who I understand the Qt thread 'framework' - and how some guys from Qt also explain it:
int main( ... )
{
MyQObject oMyObject;
oMyObject.moveToThread( &oMyThread );
// Important to use AutoConnection or QueuedConnection here!
QMetaObject::invokeMethod( &oMyObject,
"SL_DoSomething", Qt
::QueuedConnection );
oApp.exec();
}
int main( ... )
{
QApplication oApp( ... );
QThread oMyThread;
MyQObject oMyObject;
oMyObject.moveToThread( &oMyThread );
// Important to use AutoConnection or QueuedConnection here!
QMetaObject::invokeMethod( &oMyObject, "SL_DoSomething", Qt::QueuedConnection );
oApp.exec();
}
To copy to clipboard, switch view to plain text mode
The point is, that you don't derive from QThread (because so you can attach 10 objects to one thread) but move the object to the thread. Notice also, that only the work in the slots is performed in this thread (and not e.g. the constructor or other direct calls!). So you could place your methods (which were previously in the run() method) into the SL_DoSomething() slot and invoke the method by the signal-slot-mechanism.
When you call SL_DoSomething() directly (without emitting a signal or using QMetaObject::invokeMethod()) you are still in the main thread.
Bookmarks