[Interest] Automatic deletion of children of QObject

Till Oliver Knoll till.oliver.knoll at gmail.com
Wed Jun 13 18:45:26 CEST 2012


Am 12.06.2012 um 21:36 schrieb Jochen Becher <jochen_becher at gmx.de>:

> In my case childB is not a child of childA but both are children of
> parent (widgets in the same group/layout). But childB has a reference to
> childA which might be accessed in destructor.

Smells like bad gasoline: usually widgets ("Views") should not know about each other! They should operate on a common "Model" which informs their "views" anonymously ("Qt signals" *strong hint*) that something happened.

Alternatively have a "Controller" (practically the "top-level" dialog containing all the child widgets, but can really be a separate non-GUI class) which takes care of updating any sibling widget(s) when a given child widget has changed (again "signals" *hint* *hint*).

Like this you *decouple* all your different widgets (views), and they can be deleted by their parent widget without worries - in /any/ order.

The "Model" itself is deleted "in a controlled manner" (exactly once) - by, uh, the "Controller".


And yes, all this goes under MVC pattern (very basic stuff ;)).

Cheers,
  Oliver


More information about the Interest mailing list