[Interest] Taking back a widget from a QBoxLayout?

Matthew Woehlke mwoehlke.floss at gmail.com
Fri Feb 22 21:15:13 CET 2019

On 22/02/2019 14.31, Jason H wrote:
> addItem: Note: The ownership of item is transferred to the layout,
> and it's the layout's responsibility to delete it.
> removeItem: Note: The ownership of widget remains the same as when it
> was added.
> So addItem parents it as it's own, then removeItem leaves it. No 
> wonder it was crashing. This might be a bug? I don't know why
> removing it would keep the parent (the layout) then your subsequent
> call to delete deleted the widget and it's layout, so the parent was
> left dangling.  I would have expected that the parent be nulled out,
> rather than keep it referencing the layout it had just been added to
> and removed from. Perhaps a Troll can comment?

If I delete the layout, would that delete the widgets, also?

Right now, I can just delete the layout, and the widgets will remain
parented to the parent widget. If removing them from the layout also
deparented them, it would be easy to leak widgets.

It's a combination of convenience and sanity that adding a widget to a
layout adds it to the layout's widget. However, a layout is just a thing
to manage the position of widgets. It isn't intended to manage the
*existence* of widgets.


More information about the Interest mailing list