Equivalent of the gtk g_object_ref/unref functions in gtkmm?



When I look at some gtk C code, I see everywhere pointers to widgets (and other things). As i understand all gtk objects are reference counted to keep the objects alive until the last pointer is released.

How does that work in gtkmm? At first sight, gtkmm widgets doesn't seem to be reference counted, because something like this does not work (because of the private copy constructor):

Gtk::Button a, b(a);

Do I need to use smart pointers (e.g. boost::shared_ptr) for that? Does that means the underlying gtk reference counting mechanism is not used in gtkmm?

I read in the gtkmm documentation there is a Glib::RefPtr, that uses the internal gtk/gobject reference counting. If I understand that correctly, I can use this smart pointer (instead of third party implementation like boost)?

Glib::RefPtr<Gtk::Button> a(new Gtk::Button()), b(a);

But I've never seen that before, only with non-widgets objects like pixbufs and treemodels.

One of the problems I'm trying to solve is I want to create a treeview that will act as a sidebar pane in my application. And I would like to store a reference to other widgets (which are in a notebook) in the treemodel. When the user activates an item in the treeview, the corresponding widget should be displayed in the main application pane (by displaying the correct notebook page). How should this treemodel look like in gtkmm? Is a smart pointer going to interfere with the automatic memory management when I add the widget to the notebook? Do I need smart pointers at all for all this?





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]