[Interest] Automatic deletion of children of QObject

Andreas Pakulat apaku at gmx.de
Tue Jun 12 21:44:54 CEST 2012


Hi,

On Tue, Jun 12, 2012 at 9:32 PM, Jochen Becher <jochen_becher at gmx.de> wrote:

> As children are stored in a simple list and new children will be
> appended to its end it would be very simple to delete them in reverse
> order: Simply traverse the list from count()-1 to 0. This would be a
> one-line-change in method deleteChildren().
>
> Of course if I say "delete it in reverse order of creation" I mean:
> "delete it in reverse order of being added to its parent". So if you
> remove an object and re-add it to the same or another object it will be
> deleted earlier.
>

But thats just an arbitrary decision as the current behaviour is, i.e.
currently the decision done is "added first means deleted first". Changing
that decision doesn't add any benefit or clarity, since as you acknowledged
yourself the order of creation doesn't correlate in any way with the order
of adding to the children.

In addition as I said, the order of children of a QObject (or rather of
QWidget's) may change during runtime if they're raised/lowered in the
z-order. Keeping yet another list just for that when the base class doesn't
provide any guarantee of a specific order of children doesn't make that
much sense IMHO.

So in the end, I think you have a very special use-case that your require a
specific destruction order of your children and hence its just fine if you
need to take care of that yourself and cannot rely on (currently undefined)
QObject semantics.

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120612/4c6d2170/attachment.html>


More information about the Interest mailing list