Originally Posted by
jacek
Looks OK, did you try with 0 instead of "this"?
yes, but nothing changes (apparently).
I think I found something... The slot executed by the singleShot timer shall be executed by the worker thread, but is in fact executed by the GUI thread. So, I deduce that the connection created by the singleShot timer is a DirectConnection instead of a QueuedConnection. That would explain why the slot is executed by the emitting thread.
Here is how I create the worker thread, and how I create the singleShot() timer
// code from the GUI thread
otherThread = new OtherThread(this);
otherThread->start();
QTimer::singleShot(0, otherThread,
SLOT(startThread
(void)));
cout << "In GUI Thread, Thread=" << currentThread() << " ThreadID=" << currentThreadId() << endl;
// code from the GUI thread
otherThread = new OtherThread(this);
otherThread->start();
QTimer::singleShot(0, otherThread, SLOT(startThread(void)));
cout << "In GUI Thread, Thread=" << currentThread() << " ThreadID=" << currentThreadId() << endl;
QCoreApplication::processEvents(); // process the timer event
To copy to clipboard, switch view to plain text mode
here is my startThread() function (from the worker thread)
void OtherThread::startThread(void) {
cout << "In startThread() Thread=" << currentThread() << " ThreadID=" << currentThreadId() << endl;
// do some job...
}
void OtherThread::startThread(void) {
cout << "In startThread() Thread=" << currentThread() << " ThreadID=" << currentThreadId() << endl;
// do some job...
}
To copy to clipboard, switch view to plain text mode
outputs where we can see that the GUI thread executes the slot instead of the worker thread:
In GUI Thread, Thread=0x804f198 ThreadID=3078543040
In startThread() Thread=0x804f198 ThreadID=3078543040
Where is my mistake ? should QTimer::singleShot()'s receiver be something else that my otherThread ?
Bookmarks