[Qt-interest] problem using QThread
Bradley T. Hughes
bradley.hughes at nokia.com
Wed May 20 16:30:43 CEST 2009
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
More information about the Qt-interest-old
mailing list