Transparently instantiating derived widgets with Gtk::Builder



Hi folks,

I'm currently in the process of updating a 15 year old tutorial¹ to the current GTK+ 3.x release. Part of that is updating the use of libglade to use Gtk::Builder. I have read the documentation about using derived widgets² and the Gtk::Builder documentation³. However, I'm not entirely satisfied with the result.

I would like to be able to instantiate my derived widget directly with the Gtk::Builder stuff managed internally in the constructor so that the end user does not need to know about it. Is this technically possible? Can I use e.g. move-assignment with wrap() or get_widget_derived? It looks possible, but I'm unsure how safe it would be. Has anyone done this, or have any examples?

What I'm thinking of is something like:

MyWidget::MyWidget:
  Gtk::Window()
{
  Gtk::Builder builder;
  builder.add_from_resource(res);
  MyWidget *tmp
  build.get_widget_derived(name, tmp);
  *this = std::move(*tmp);
}

but I'm not sure about the safety of it.


Thanks all,
Roger


¹https://gitlab.com/codelibre/ogcalc/tree/master/gtk/C++
²https://developer.gnome.org/gtkmm-tutorial/stable/sec-builder-using-derived-widgets.html.en
³https://developer.gnome.org/gtkmm/stable/classGtk_1_1Builder.html#af8b9510f6146cde5364f830494114191


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]