[Interest] 答复: moveToThread and object deletion

pengliang(彭亮) pengliang at founder.com
Fri Mar 15 01:37:03 CET 2013


Yes,

Api doc says:

Warning: This function is dangerous and its use is discouraged. The thread can be terminated at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to clean up after itself, unlock any held mutexes, etc. In short, use this function only if absolutely necessary.

 

 

 

 

-----邮件原件-----
发件人: interest-bounces+pengliang=founder.com at qt-project.org [mailto:interest-bounces+pengliang=founder.com at qt-project.org] 代表 Thiago Macieira
发送时间: 2013年3月15日 1:51
收件人: interest at qt-project.org
主题: Re: [Interest] moveToThread and object deletion

 

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/cec1ec5f/attachment.html>


More information about the Interest mailing list