[Interest] Automatic deletion of children of QObject

Arnold Krille arnold at arnoldarts.de
Thu Jun 14 00:55:49 CEST 2012


On 13.06.2012 23:35, Jan Kundrát wrote:
> On 06/13/12 22:50, Jochen Becher wrote:
>> Of course it is not a bad idea to access siblings in a destructor. Why
>> should it? If destruction follows in a known and reliable way there is
>> no reason to avoid it. I do it to check some post-conditions using
>> Q_ASSERT() to ensure all resources were freed and that involves some
>> checks in siblings.
> QObject's children are destroyed in an order which is not specified,
> hence it's a bad idea to access "siblings" in a QObject's destructor.

As far as I understand it, it is actually save to access child objects
inside the destructor. The childs get deleted in QObjects destructor
which is called after the destructors of the derived classes. In fact I
often did delete the childs in my own loop as that one was protected by
the mutex other objects used while adding or deleting childs of this
object. Relying on QObjects destructor was in that situation open for
race-conditions.

Have fun,

Arnold
-- 
Dieses Email wurde elektronisch erstellt und ist ohne handschriftliche
Unterschrift gültig.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120614/fc7e78d6/attachment.sig>


More information about the Interest mailing list