Yes, Gtk::Builder::get_widget_derived() calls the derived
widget's constructor with only the two parameters shown in the
gtkmm tutorial. The bug
https://bugzilla.gnome.org/show_bug.cgi?id=134161 discusses this
issue. I would probably solve a situation such as yours by splitting the construction of the derived widget into the restricted constructor with just two parameters + a DerivedWidget::init() function with other parameters that I would call right after get_widget_derived(). An alternative: Make a get_data() function that can be called from the derived widget's constructor. Kjell Den 2015-01-04 08:16, Adam
Nielsen skrev:
Hi all, In the example given here: https://developer.gnome.org/gtkmm-tutorial/stable/sec-builder-using-derived-widgets.html.en A call to Gtk::Builder::get_widget_derived() is used to create an instance of the derived dialog class. The class then sets up the widgets in its constructor. However from the example it's unclear how, in a more complex program, you would access data external to the class from within that constructor. For instance the example simply attaches an event handler to a button, but in my situation I want to populate a ListBox with values stored in a data structure loaded earlier in the application. Normally I would pass the data structure as an extra parameter in the constructor, so the constructor can access the information it needs to set up the widgets appropriately. However Gtk::Builder::get_widget_derived() seems to require a fixed constructor form, so I can't supply any additional information to the constructor. How is this situation typically handled? Is there a best-practice for this scenario? Many thanks, Adam. |