I know that QThreads are a tricky issue for most. I've read through a lot of examples and documentation to setup my threading correctly under QT. The 2 methods seem to be sub-classing QThread (which although the documentation says to do this, it is apparently the incorrect way) and the other is subclassing QObject and then moving it to a thread. Trying both methods I was unable to get a simple signal in the thread to connect to a slot in my main thread.
For the first method if I did not use moveToThread(this) in the subclassed QThread constructor, it would not execute in a new thread, but the signals worked. Using moveToThread(this) caused the connection to be broken in some way.
Trying it the 2nd method, my signals in the worker object worked until I moved them to a QThread.
Are there any known issues with using QThread under QT 4.6.3 and compiling with MSVC 2010 on Win7 x64( the app is compiled as 32-bit)?
The signal I'm emitting is a QString (declare as: void StringSignal(QString&);, used as: emit StringSignal(QString("Hello"))
In the first method the connection is made as:
connect(&thread,SIGNAL(StringSignal(QString&)),this,SLOT(SignalSlot(QString&)));)
connect(&thread,SIGNAL(StringSignal(QString&)),this,SLOT(SignalSlot(QString&)));)
To copy to clipboard, switch view to plain text mode
My code isn't any different than the Mandelbrot example (for the first method I tried). I call a function in the QThread that sets some values and either starts the thread if it isn't running or wakes the QWaitCondition.
Bookmarks