[Qt-interest] QThread run() method

Jeroen De Wachter jeroen.dewachter at barco.com
Mon Aug 31 13:34:04 CEST 2009


One might suggest exiting the thread cleanly and just calling exit() or
quit() from within the thread instead of terminating it (while it may
hold a mutex, be in the middle of modifying data or anything else of the
sort)

See the QThread documentation for more details (and especially the
warning in the description of the terminate() method)

On Mon, 2009-08-31 at 16:47 +0530, Rehan wrote:
>     Below code may resolve your issue.
> 
>  
> 
>     if (th->running())
> 
>     {
> 
>         th->terminate();
> 
>         th->wait();
> 
>     }
> 
>  
> 
>  
> 
>  
> 
> Regards,
> 
> Rehan
> 
> 
>                                    
> ______________________________________________________________________
> From:qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Sarvesh Saran
> Sent: Monday, August 31, 2009 4:06 PM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] QThread run() method
> 
> 
>  
> 
> 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
> 
>  
> 
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest


DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.





More information about the Qt-interest-old mailing list