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

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Jan 20 10:20:34 CET 2010


John McClurkin wrote on Tuesday, January 19, 2010 7:42 PM:

> > ...
> Qt does support multi threaded applications,

This statement in itself is a bit too strict ;) Multithreading in Qt is very well supported (There is QMutext and Co. for a reason ;)

> but all drawing must be
> done in the thread that calls main(); 

... but off course you actually meant "Multithreaded painting is not possible in Qt" ;)

> If you want to update drawing
> from a non-gui thread, use the signal-slot mechanism. That is, have
> the non-gui thread send a signal to a slot in the gui thread that
> calls update on your widget. See the "Thread Support in Qt" section

I am not so sure whether it is really not possible calling QWidget::update() from a non-GUI thread? After all: "This function does not cause an immediate repaint; instead it schedules a paint event for processing when Qt returns to the main event loop." (http://doc.trolltech.com/4.6/qwidget.html#update)

So calling update() does not immediatelly trigger a painting, but a "paint requested" event is inserted into the event loop. The question off course is into /which/ event loop, since every thread can have its own (http://doc.trolltech.com/4.6/threads-qobject.html#per-thread-event-loop). And if the calling thread has its own event loop, what happens then? But then again, the docs talk about the "main event loop", which suggests that the painting is really only done in the "main" thread (triggered by the "main event loop").

To be confirmed...

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



More information about the Qt-interest-old mailing list