[Qt-interest] Question regarding QThread object affinity

Thiago Macieira thiago.macieira at trolltech.com
Mon Jun 8 21:07:41 CEST 2009


Patric wrote:
>Hello,
>I have a question regarding threads.
>Let's assume we have a A. In that class, we have instance of class B as
> a member. We also have a QThread - class C. The class B member is not a
> pointer.
>What if I call "member_B.moveToThread()", how will the object member_B
> be deleted ? Usually, it'll be deleted when the object_A is destroyed.
> But now it's moved to another thread, who is responsible for it's
> deletion ?

If it's not a pointer, it's deleted when the scope is deleted: that is, 
when object_A is destroyed.

And since it's been moved to another thread, you cannot delete it there. 
That means you MUST move it back before letting it be destroyed.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090608/d104555c/attachment.bin 


More information about the Qt-interest-old mailing list