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
deleted.
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.
Moritz
#include <iostream>
using namespace std;
#include <gtkmm.h>
const char gladefile[] =
"<?xml version='1.0' encoding='UTF-8'?>"
"<interface>"
" <!-- interface-requires gtk+ 3.0 -->"
" <object class='GtkWindow' id='window1'>"
" <property name='can_focus'>False</property>"
" <child>"
" <object class='GtkButton' id='button1'>"
" <property name='label' translatable='yes'>button</property>"
" <property name='use_action_appearance'>False</property>"
" <property name='visible'>True</property>"
" <property name='can_focus'>True</property>"
" <property name='receives_default'>True</property>"
" <property name='use_action_appearance'>False</property>"
" </object>"
" </child>"
" </object>"
"</interface>";
class DerivedButton : public Gtk::Button
{
public:
DerivedButton(BaseObjectType* cobject, const
Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::Button(cobject)
{
cout << "DerivedButton::ctor" << endl;
}
virtual ~DerivedButton()
{
cout << "DerivedButton::dtor" << endl; // <--- This line never
gets executed
}
};
class MainWindow : public Gtk::Window
{
private:
DerivedButton* m_pButton;
public:
MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>&
refBuilder)
: Gtk::Window(cobject)
, m_pButton(NULL)
{
cout << "MainWindow::ctor" << endl;
refBuilder->get_widget_derived("button1",m_pButton);
}
virtual ~MainWindow()
{
cout << "MainWindow::dtor" << endl;
}
};
int main(int argc, char* argv[])
{
Gtk::Main kit(argc,argv);
Glib::RefPtr<Gtk::Builder> builder =
Gtk::Builder::create_from_string(gladefile);
MainWindow* main_win = NULL;
builder->get_widget_derived("window1", main_win);
if (main_win)
{
kit.run(*main_win);
}
delete main_win;
return 0;
}
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list