I'm having some issues in developing with gtkmm.
Usually all the containers want a ref to a Gtk::Widget object.
That makes sense, it works and all those things, but it forces you to keep the objects on the heap*
As far as I understand, when any Gtk::Widget goes out of scope (eg is destructed) it will notify the parent object and basically will be removed from the GUI.
The problem is when you have to populate containers (like Gtk::Notebook) on the fly, with dynamic data.
Naturally, if you use this approach
_nb.append_page(*(new Gtk::Label("test")), "label");
it works, as seen as the object is never destroyed.
In case I have to replace elements of a container such allocated I can just do the following:
Glib::ListHandle<Widget*> c_list = nb.get_children();
for(Glib::ListHandle<Widget*>::iterator it = c_list.begin(); it != c_list.end(); ++it)
The point is that this way the destructors should be automatically called, the parent container notified, and memory then freed as well.
I don't like this approach because is not exception safe and is definitely not elegant.
Is there any better solution/more elegant way to do all this dynamic gui generation?
*Basically the children Gtk::Widget have to be allocated during the whole lifetime of the parent container. Naturally objects on the stack work as well as long the parent container is destroyed before they are.