[Qt-interest] QThread run() method

Sarvesh Saran Sarvesh.Saran at synopsys.com
Mon Aug 31 13:35:38 CEST 2009


Hi,

Thanks for the reply Andre..it cleared a few things up.

Thanks,
Sarvesh

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Andre Somers
Sent: Monday, August 31, 2009 4:34 PM
To: Qt-interest
Subject: Re: [Qt-interest] QThread run() method

Sarvesh Saran wrote:
>
> Hi,
>
> This question is a little naïve but I still need an answer to it.
>
> What happens to a QThread after the run method is done? The
> documentation says the execution ends when you return from run. Does
> that mean the thread object ceases to exists ? for some reason my
> thread manages to receive a signal and execute a slot even after the
> run method is done .i.e.
>
> Qthread *th = new Qthread();
>
> th->start
>
> ...
>
> ..
>
> And later when the thread has finished its run method..
>
> th->sendStopSignal(); (thread is not running at this point,
> th->isRunning() returns false)
>
> delete th;
>
> th=NULL;
>
> (for some reason th receives this signal and executes the slot)
>
> Thanks,
>
> Sarvesh
>
The obvious answer would be that you ran the exec() method in the run()
method (the default implementation). That starts an eventloop that makes
the thread able to receive signals (among other things). That behaviour
is totally expected.
In no case will a QThread object itself be destroyed or something like
that if the running of a thread ends. The QThread lives in the thread
that made it (by default anyway). The new thread is managed by the
QThread, but is not the QThread itself.

André

_______________________________________________
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