[Qt-interest] QThread run() method
Andre Somers
andre at familiesomers.nl
Mon Aug 31 13:03:39 CEST 2009
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é
More information about the Qt-interest-old
mailing list