[Qt-interest] Is it safe to connect different threads by Qt::DirectConnection?
donglongchao
donglongchao at 163.com
Sat Dec 5 15:29:28 CET 2009
在2009-12-05,"Mihail Naydenov" <mlists at ymail.com> 写道:
>>From: donglongchao <donglongchao at 163.com>
>>To: Qt Devel qt-interest at trolltech.com>
>>Sent: Sat, December 5, 2009 6:45:50 AM
>>Subject: [Qt-interest] Is it safe to connect different threads by Qt::DirectConnection?
>>
>>
>>Hi,
>>
>>...
>>.Now I have one GUI thread and one work thread and there is a QTimer object lives in my work thread.
>
>>...
>
>>Since the QTimer object and the work thread live in different threads
>
>So, where does the timer lives ?
>
>Also why is that "if
>I do not set the fifth parameter of QObject::connect(...),the slot function
>will run in GUI thread"
>...setting the fifth cannot change that...
>
>You should post some code, I (completely) fail to understand your configuration, and what the problem is.
class workthread:QThread
{
public slot:
void slot_fun()
{ some time-consuming code here;}
}
void workthread::run()
{
QTimer timer;
QObject::connect(&timer,SIGNAL(timeout()),this,SLOT(slot_fun()));
timer.start(...);
}
GUI thread(main thread)
int main(int argc,char *argv[])
{
mythread = new workthread;
}
So now I want the slot function slot_fun() to run in the work thread ,not in the GUI thread.According to the documents,if the fifth parameter is not set,slot_fun() will run in the GUI thread which will cause the UI unresponsive.If the fifth parameter is set to be Qt::DirectConnection, slot_run() will run in work thread.This is what I need.But I want to know if it is thred-safe to do like this or if there is a better way I do not know.
>MihailNaydenov
>
>>...
>>
>>Longchao.
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091205/c8987e42/attachment.html
More information about the Qt-interest-old
mailing list