Search code examples
c++gtkmmglade

Access to GtkLabel by the GtkBuilder


How can I access the label elements (GtkLabel) to change the text at runtime? With this code, I get a compile error.

lottozahlen.cpp

Gtk::Window* pWindow = 0;
Gtk::Label* pLabel = 0;

int
main (int argc, char **argv)
{
  Gtk::Main kit (argc, argv);
  Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create_from_file ("ui/main.glade");

  refBuilder->get_widget ("mainWindow", pWindow);
  refBuilder->get_widget ("label_1", pLabel);

  kit.run (*pWindow);

  return (0);
}

Compiler Error

/usr/include/gtkmm-3.0/gtkmm/builder.h:628:93: error: incomplete type ‘Gtk::Label’ used in nested name specifier
 widget = dynamic_cast<T_Widget*>(this->get_widget_checked(name, T_Widget::get_base_type()));

Solution

  • Presumably you just need to include the gtkmm/label.h header. Including gtkmm.h should give you everything you need.