[Qt-interest] problem using QThread
Sarvesh Saran
Sarvesh.Saran at synopsys.com
Wed May 20 16:55:16 CEST 2009
Hi,
Thanks for the help!!
Thanks,
Sarvesh
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Bradley T. Hughes
Sent: Wednesday, May 20, 2009 8:01 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] problem using QThread
Sarvesh Saran wrote:
> Hi,
>
> I have a main window where one of its widgets launches a QThread. Unfortunately an exit(1) in the thread closes the main window too. I'm not sure why this is happening. It could be because of the way I launch the thread or something else.
>
> Basically, I am doing the following:
>
>
> 1. (in mainwindow.cpp)
> Mywidget *widget = new Mywidget(this);
>
>
> 2. .....then in MyWidget.cpp
> MyThread *th = new MyThread(this);
> Connect (this,SIGNAL(killall()),th,SLOT(KillThread()));
> th->start();
The KillThread() slot is being called from the GUI thread because the thread
affinity of MyThread is not to itself[1][2].
[1] "Like other objects, QThread objects live in the thread where the object
was created -- not in the thread that is created when QThread::run() is
called."
http://doc.qtsoftware.com/4.5/threads.html#accessing-qobject-subclasses-from-other-threads
[2] See pages 33-43 of
http://chaos.troll.no/~ahanssen/devdays2007/DevDays2007-Threading.pdf
--
Bradley T. Hughes (Nokia-D-Qt/Oslo), bradley.hughes at nokia.com
Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list