[Qt-interest] Is it safe to connect different threads by Qt::DirectConnection?

Scott Aron Bloom Scott.Bloom at sabgroup.com
Sat Dec 5 06:33:41 CET 2009


If you don't set the fifth parameter, its set to Auto connection, which
unless you need a blocking connection, is what you want.

 

When the timer goes off, it will create an event in the worker threads
event loop, when the event gets processed, it will be "converted" back
to a signal and emitted which will run the slot

 

Scott

 

From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of donglongchao
Sent: Friday, December 04, 2009 8:46 PM
To: Qt Devel
Subject: [Qt-interest] Is it safe to connect different threads by
Qt::DirectConnection?

 

Hi,

I have a question when I develop my muti-thread programme.Now I have one
GUI thread and one work thread and there is a QTimer object lives in my
work thread.And I want to connect the timeout() signal of the QTimer
object to a slot of my work thread.Also I want the slot function to run
in the work thread not the GUI thread.Since the QTimer object and the
work thread live in different threads,if I do not set the fifth
parameter of QObject::connect(...),the slot function will run in GUI
thread.If I set the fifth parameter to be Qt::DirectConnection,then the
slot will run in the thread where the QTimer object lives.This is what I
want.So I want to know if it is safe to do like this?Or is it the right
way to achieve my requirement?If not,what is the right way?Could anyone
help?Any suggestion will be appreciated.
Thanks in advance.

Longchao.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091204/bd492744/attachment.html 


More information about the Qt-interest-old mailing list