thanks for the article. now i see it is not necessary to subclass QThread, but, honestly, i don't see much difference. We can write something like
Worker *worker = new Worker;
worker->moveToThread(thread);
// now start the thread
thread->start();
QThread *thread = new QThread;
Worker *worker = new Worker;
worker->moveToThread(thread);
// now start the thread
thread->start();
To copy to clipboard, switch view to plain text mode
or we can subclass it and move the object in the constructor:
MyThread::MyThread()
{
myobject.moveToThread(this);
}
MyThread::MyThread()
{
myobject.moveToThread(this);
}
To copy to clipboard, switch view to plain text mode
in both cases object is moved to the thread before it is started, so in both cases the object seems to be moved to the thread interface that QThread is.
and i don't move thread to itself - i move objects to a thread (see my thread declaration).
Bookmarks