Hi Jochen,

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.

In certain circumstances, a solution which uses QPointer can be handy,
ie. when you just want to take an optional cleanup like "hey buddy, if
you're still here, I'd like to let you know that I'm gone so that you
don't count on me being around anymore". However, it has big drawbacks
-- because you cannot affect the order of destruction reliably, you
cannot test both ways and it can be very easy to suddenly rely on one
particular order.

> I wouldn't name another developer's solution a bad idea without knowing
> why the solution was chosen...

In this case, your solution is bad because you depend on an order of
things which are not declared to be stable, sorry.

Cheers,
Jan

-- 
Trojita, a fast e-mail client -- http://trojita.flaska.net/

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to