On 2013-06-13 11:18, Dmitriy Igrishin wrote:
>
>     Who owns the contents? WStackedWidget, or WMenuItem, or?
>
>   WMenuItem.
>
>     Who owns the menu items? WMenu, or?
>
> WMenu.
>
>     Why doesn't WMenu have a setContentsStack?
>
>     Why doesn't WMenuItem have a setContents?
>
> I believe because it does not worth it.
> Can you please explain why do we need these stuff?
> What real example usage?
>
>

Thanks for the reply. I'm creating classes the larger part of the widget 
tree as values, to minimize allocations. I'm assuming the ownership / 
memory model of Wt is the same as that of Qt.

E.g., if you write

WWidget parent_;
WWidget child_( &parent );

everything will be ok, because destruction and deregistration is done in 
reversed order.

With WMenuItem and friends, stuff becomes a bit more confusing, because 
you need to pass its child widget, and, more importantly, its child 
widget needs to be heap allocated.

E.g., if you write

WStackedWidget stack_;
WMenu menu_( &stack_, &some_parent );
SomeContent contents_;
WMenuItem some_item_( "my label", &contents_ );

you will be in trouble, because contents_ will be deleted twice. If we 
were able to write

WStackedWidget stack_;
WMenu menu_( &stack_, &some_parent );
WMenuItem some_item_( "my label" );
SomeContent contents_;
some_item_.setContents( contents_ );

and assuming the same ownership model is in place, this wouldn't fail.

Having said all this, I still don't understand the condition of the 
destruction in WMenuItem. Why doesn't this read

~WMenuItem() {
    if ( contents_ ) {
      delete contents_;
    }
}

Thanks,

Rutger




------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to