[Qt-interest] QWaitCondition prevents signals from calling slots
Thiago Macieira
thiago.macieira at trolltech.com
Thu May 21 00:15:01 CEST 2009
Jonathan Wong wrote:
>So is it true that QTimer needs the event loop to be running in order to
> function? Say QTimer in threadA, so threadA must not be blocked (or
> waiting on QWaitCondition).
Correct.
>threadA blocked, main thread blocked (via objectB's waiting), QTimer in
> threadC unblocked.
>
>That didn't function as per the theory about QTimer needing a running
> event loop. threadC is not blocked at all.
>
>It does seem that the theory doesn't apply whenever the main thread is
> blocked. Seems like it is a terrible thing to do, blocking main thread?
The problem here is different.
I explained how the timer runs and you seem to have understood that.
However, the timer running and getting emitted is the first of two steps
only. The second step is calling of your slot. And I think you're now
blocked here.
And I think the problem you're facing is this:
>> One more thing: avoid having slots in the QThread-derived class
>> itself. Remember that the QThread-derived object is created in another
>> thread (it can't be created on its own thread because that thread
>> isn't running yet!), so it has thread affinity to the creating thread.
>> That may cause unexpected behaviour, so the recommendation is to avoid
>> it.
>
>Yes, I suppose you saw I was trying to parent the QTimer in ThreadA? :)
>
>I suppose the slots for a QThread-derived class would be called in
> another thread (not the class's run() thread).
Correct. Note that his applies also to any objects created in the QThread
object's constructor. So you should create the objects only in the run()
method.
What I guess is happening is that your thread C (above) did fire its timer.
However, the receiver object belonged to one of the other two threads.
Since those two threads are blocked, the slot hasn't been called yet.
Unblock the threads and you may see the slot getting called.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Software
Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090521/2e840ac3/attachment.bin
More information about the Qt-interest-old
mailing list