[Interest] moveToThread and object deletion

Etienne Sandré-Chardonnal etienne.sandre at m4x.org
Fri Mar 15 00:33:23 CET 2013


Thanks for the answer. This leads me to two questions:
1) It's then unsafe to destroy the QThread in a slot connected to
"finished", as it is in fact "aboutToFinish", am I right? But deleting
after terminate() signal or after return from wait() is safe.
2)One poorly documented thing about QThread, is where are supposed to be
called exit() and quit(). While exit() naming suggests that it should be
called from the thread to terminate as in posix, the slot nature of quit()
suggests it should be called from the thread where QThread lives, ie the
parent thread. But quit calls exit(0). That's confusing...
In other words, is it safe/clean to:
 - call this->thread()->quit()   (quit called from the thread)
or
 - call workerThread->quit()   (quit called from the parent thread where
QThread lives)



Thanks,

Etienne

Etienne


Date: Thu, 14 Mar 2013 10:51:04 -0700
> From: Thiago Macieira <thiago.macieira at intel.com>
> Subject: Re: [Interest] moveToThread and object deletion
> To: interest at qt-project.org
> Message-ID: <1480922.c4s92Zr3RZ at tjmaciei-mobl2>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On quinta-feira, 14 de mar?o de 2013 18.33.38, Etienne Sandr?-Chardonnal
> wrote:
> > Is it safe and correct to connect QThread::quit() and
> QThread::terminated()
> > to Worker::deleteLater() ? I would say no, as signal/slot mechanism will
> > try to run deleteLater() in the workerThread, which is not running
> anymore,
> > so object deletion will never happen.
>
> That's actually very good thinking, showing you understand how threads
> work.
>
> But we added a little bit of magic to the event dispatcher: after the
> finished() signal is emitted, it runs all events once again to process
> object
> deletions. You couldn't have known that by simple analysis.
>
> In other words, you can connect finished() to deleteLater() and it will
> work.
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130315/46e5614e/attachment.html>


More information about the Interest mailing list