[Qt-interest] Which one is faster?

Arnold Krille arnold at arnoldarts.de
Thu Nov 19 09:20:49 CET 2009


Hi,

On Thursday 19 November 2009 07:43:33 Rainer Wiesenfarth wrote:
> 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:

Okay, I have run this issues for several years now :-)

> (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.

Actually QueuedConnections _are_ events sent per postEvent(). So (1) and (2) 
are both the same. Only with (1) you get the data copying done by qt but have 
to register your own types with the meta-system. With (2) you have to create 
your own events if you want to exchange your own data-types...

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091119/a1568f1d/attachment.bin 


More information about the Qt-interest-old mailing list