[Qt-interest] Can Update() be called other than GUI thread

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Jan 20 15:15:42 CET 2010


Arnold Krille wrote on Wednesday, January 20, 2010 2:47 PM:

> On Wednesday 20 January 2010 01:15:26 Malyushytsky, Alex wrote:
>> You can't call update() directly from any thread except gui thread.
> 
> Actually I think you can. 

That was also my idea.


> Of course update() is also a slot which you can trigger via a
> QueuedConnection. 

That would probably be the safest way - unless update() *really* puts the "repaint requested" event into the *main* Qt event queue, the queue which runs in the "main thread" (also in the case where the non-GUI thread has its own event queue). Then you could also call QWidget::update() from any thread. The Qt docs actually suggest so: "...a paint event for processing when Qt returns to the main event loop." (http://doc.trolltech.com/4.6/qwidget.html#update)

When Qt returns to the *main* event loop sounds to me like the "repaint request" event would only be handled in the "main" thread. But not sure whether "main event queue" is /really/ equivalent to "the event queue which runs in the main thread"...

Then again, there are /no/ explicit words saying that calling update() would be safe in any thread: http://doc.trolltech.com/4.6/threads-modules.html (Painting in Threads), something like "Painting must only be done in the main thread, but calling update() is safe to be called from any thread".

So someone could look into the implementation of update() and tell us :) Or just don't bother and always call it with a queued connection, as suggested by Arnold :)


Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list