Accessing widgets

To access a widget, for instance to show() a dialog, use the get_widget() method, providing the widget's name. This name should be specified in the Glade Properties window. If the widget could not be found, or is of the wrong type, then the pointer will be set to 0.

Gtk::Dialog* pDialog = 0;
refXml->get_widget("DialogBasic", pDialog);

libglademm checks for a null pointer, and checks that the widget is of the expected type, and will show warnings on the command line about these.

Remember that you are not instantiating a widget with get_widget(), you are just obtaining a pointer to one that already exists. You will always receive a pointer to the same instance when you call get_widget() on the same Gnome::Glade::Xml, with the same widget name. The widgets are instantiated during Glade::Xml::create().

get_widget() returns child widgets that are manage()ed (see the Memory Management chapter), so they will be deleted when their parent container is deleted. So, if you get only a child widget from libglademm, instead of a whole window, then you must either put it in a Container or delete it. Windows (such as Dialogs) can not be managed because they have no parent container, so you must delete them at some point.

Example

The basic example in the libglademm package shows how to load a Glade file at runtime and access the widgets with libglademm.