[Qt-interest] Is it safe to connect different threads by Qt::DirectConnection?
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Sat Dec 5 07:30:18 CET 2009
Yes.. you can do that.. it will only be as object safe as the worker threads objects are…
Good luck with it.. and I wouldn’t use “sender()”
Scott
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of donglongchao
Sent: Friday, December 04, 2009 10:13 PM
To: Qt Devel
Subject: Re: [Qt-interest] Is it safe to connect different threads by Qt::DirectConnection?
Sorry....:-)
But I think I can do it.According to the documents,if I have the fifth parameter to be Qt::DirectConnection,the slot will run in the sender's thread(the work thread),not necessary the receiver's thread(the GUI thread).That is exactly what I want.But I do not know if it is thread-safe to do like that or there is a better way.
Longchao
在2009-12-05,"Scott Aron Bloom" <Scott.Bloom at sabgroup.com> 写道:
Please don’t respond directly to me…
You will not be able to call it with a direct connection.. Your choice to cross thread boundries is either Queued or Blocking.
The “auto” defaults to queued when it goes from one thread to another, it its in the same thread then its direct, if you need blocking, ie the sending thread blocks until the receiving thread is finished responding to the signal, then you want blocking.
Scott
From: donglongchao [mailto:donglongchao at 163.com]
Sent: Friday, December 04, 2009 9:50 PM
To: Scott Aron Bloom
Subject: Re:Re: [Qt-interest] Is it safe to connect different threads by Qt::DirectConnection?
The slot will run a time-consuming task ,so I want it run in the work thread ,not the GUI thread,in order to keep the UI responsive.Will it be safe to call with Qt::DirectConnection?
在2009-12-05,"Scott Aron Bloom" <Scott.Bloom at sabgroup.com> 写道:
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/f3825774/attachment.html
More information about the Qt-interest-old
mailing list