Re: gtkmm::builder - derived child widget's destructor is not called

Your question is not stupid. I believe Gtk::Builder::get_widget() and Gtk::Builder::get_widget_derived() handle reference counts in the wrong way.

Gtk::Builder::get_widget() adds a reference each time it's called. Gtk::Builder::get_widget_derived() adds a reference the first time it's called on a certain widget. Other gtkmm methods that return a Widget* don't add references. Adding references is appropriate for methods that return a Glib::RefPtr<Something>, but not for methods that return a plain Something pointer.

If you like, you can file a bug report. Unfortunately there is a risk with fixing the bug before the release of gtkmm 4 (which is probably not soon). A fix might break working programs, because some users of gtkmm might have adapted their programs to the present behaviour by adding some widget->unreference().


2014-06-06 08:42, Moritz Peter skrev:
Hello everybody,

I'm using gtk::builder to create a user-interface. To illustrate my
problem I simplified the interface to a window containing only one
button. I retrieve both widgets (window and button) using
"get_widget_derived" since they are modified by the code.
My problem arises at the end of the program, when the widgets should be
The manual states that "toplevel" widgets (windows and dialogs) must be
deleted by the user, so I delete the window as prescribed. As the button
is inside a container (the window) I expect the button to be managed and
therefore being deleted automatically. This is not the case. The
destructor of the button is never called.
What is my mistake? Or is this a bug?

Attached you'll find a simple test program that you can compile using
g++ `pkg-config --libs --cflags gtkmm-3.0` gladetest.cpp
There you will directly see my problem.

I hope, I'm not bothering you with my stupid question.
Thanks in advance.


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