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().

Example

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