Hey Peter,

2008/7/10 Peter Klar <[EMAIL PROTECTED]>:
> so far I understood objects derived from WObject are automatically deleted
> once their parent is deleted (similar to Qt QObjects), e.g.
> new WLabel(parent)
> is automatically deleted once parent is deleted.
>
> When only using
> new WLabel()
> it has to be deleted manually.

That is indeed the case (as in Qt).

> I recognized that when using (nested) layouts at least within a
> WContainerWidget I have to create my WObjects without making it a child of
> the parent WContainerWidget, else I get a warning like
> Warning: WContainerWidget: ignoring twice addWidget!

The warning has been fixed a few days ago in CVS, and the behaviour
has been documented better.

The warning has been changed to read "WContainerWidget::addWidget():
reparenting widget." only if a widget changes parent as result of
adding it to a container. Otherwise, the whole operation is ignored
(which would be in your case).

Thus, you can add the widget to a container immediately. If not, the
layout will do this for you.

> Simplified ctor:
>
> SampleClass::SampleClass(...) : WContainerWidget(...)
> {
>        WVBoxLayout* vLayout = new VBoxLayout(this);
>        WGridLayout* gridLayout = new WGridLayout();
>        WLabel* foobar = new WLabel();
>
>        vLayout->addItem(gridLayout);
>        gridLayout->addWidget(foobar, 0, 0);
> }
>
> This works fine but I'm unsure whether I have to delete foobar manually.

So, you are find, since the layout will parent the widget itself.

> If I specify 'this' (derived from WContainerWidget) to the WLabel ctor I get
> the above warning message.

Which was a bit confusing, and this behaviour is no longer.

> I just want to be sure whether WObjects added to a WLayout become part of
> the object tree and are automatically deleted.
>
> Also I'm unsure about the WLayouts itself as they don't derive from
> WObject - what's about them in this context?

This has been documented now as well: the container assumes ownership
of the layout (included nested layouts).

Admittedly, the 2.1.4 release, the maiden release for our layout
managers, was indeed a bit confusing with respect to all this. It also
contained some bugs related to the life-cycle of layouts that are
added to a container that has already been rendered, and the behavior
of WContainerWidget::clear() with respect to layouts.

These have all been fixed in CVS.

Regards,
koen

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to