[Qt-interest] Which one is faster?

Rainer Wiesenfarth Rainer.Wiesenfarth at inpho.de
Thu Nov 19 07:43:33 CET 2009


From: donglongchao
> I am working on an app of muti-threads and I have a question 
> about threads.I have two threads now,one is UI thread and the 
> other one is a working thread.So now in my working thread,I 
> want to ask the UI thread to update some widget.There are 
> several way to do that.
> (1) Emit a signal and connect it to the slot of the 
> widget.(2)Use postEvent (3)Use sendEvent (4)Use a QTimer with 
> start(0,TRUE) (5)Creat a single shot timer with static single Shot.
> So I want to know which one is faster?Or there is a faster 
> way I didn't mention above?Of course,we should test them 
> under the same situation(the sender and the receiver live in 
> different threads).

I haven't run tests on this, but would assume this:

(4) and (5) both use a signal/slot connection when the timer expires, thus
both of them are certainly slower than (1)

(3) will not work, as sendEvent() does not pass thread boundaries

(2) was the pre-Qt 4 approach, when there was no Qt::QueuedConnection
available

(1), in conjunction with Qt::QueuedConnection, is the Qt4 approach for
situations like yours.

I assume the Trolls have optimised their favourite approach, so by using (1)
you should be on the safe side.

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

-- 
INPHO GmbH * Smaragdweg 1 * 70174 Stuttgart * Germany
phone: +49 711 2288 10 * fax: +49 711 2288 111 * web: www.inpho.de
place of business: Stuttgart * managing director: Johannes Saile
commercial register: Stuttgart, HRB 9586
Leader in Photogrammetry and Digital Surface Modelling
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6878 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091119/27b3334c/attachment.bin 


More information about the Qt-interest-old mailing list