> Sent: Friday, February 22, 2019 at 1:04 PM
> From: "René J.V. Bertin" <rjvber...@gmail.com>
> To: "Jason H" <jh...@gmx.com>
> Cc: "interest@qt-project.org Interest" <interest@qt-project.org>
> Subject: Re: [Interest] Taking back a widget from a QBoxLayout?
>
> On Friday February 22 2019 17:45:05 Jason H wrote:
> 
> >I am not 100% sure, it's been a while, but I would assume that the layout is 
> >not the true parent, combined is.
> 
> The docs aren't exactly clear on this subject, at least not with the sort of 
> reading glasses I usually have on when I don't exactly want to be reading 
> them ;)
> 
> >The "delete combined" will delete child widgets a and b.
> 
> That much is clear, because it takes ownership of the layout (THAT is clearly 
> documented).
> 
> >You need to unparent them, then delete combined. Layouts allocate pixels and 
> >resize things, they don't own them, AFAIK.
> 
> Setting their parent back to what it was (nullptr) did the trick indeed, 
> regardless of who really owned them.
> 
> I guess I didn't try this yet because I'm never certain if taking ownership 
> is really only done through making yourself a parent.
> 

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?
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to