[Qt-interest] problem using QThread

Donal O'Connor donaloconnor at gmail.com
Wed May 20 16:13:14 CEST 2009


A process is made up of several threads. (Threads arn't separate processes!)
When you exit from a thread, you exit the process so this is what happens.
If you want to kill the thread, use the terminate() method.

On Wed, May 20, 2009 at 3:09 PM, Sarvesh Saran
<Sarvesh.Saran at synopsys.com>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();
>
>
>
> And ..
>
> on_killButton_clicked()
>
> {
>
> Killall();
>
> }
>
>
>
> 3.       Finally in mythread.cpp
>
> KillThread()
>
> {
>
> exit(1);
>
> }
>
>
>
> Unfortunately slot KillThread causes the mainwindow to exit out.
>
>
>
> Is there something I am missing?
>
>
>
>
>
> Thanks,
>
> Sarvesh
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090520/59d89f1f/attachment.html 


More information about the Qt-interest-old mailing list