GNOME Bugzilla – Bug 131566
libglademm can't create a derived GtkOptionMenu
Last modified: 2011-01-16 23:33:36 UTC
If I derive a new widget from GtkOptionMenu, I can't create it from a Glade interface: a empty menu is created, and I see this error: (gladeexamplewindow:8373): Gtk-CRITICAL **: file gtkmenu.c: line 865 (gtk_menu_popup): assertion `GTK_IS_MENU (menu)' failed (gladeexamplewindow:8373): Gtk-CRITICAL **: file gtkmenu.c: line 1088 (gtk_menu_get_active): assertion `GTK_IS_MENU (menu)' failed However, the widget /does/ contain a menu, since I can manipulate it from within the C++ object. I'll attach a test case. Regards, Roger
Created attachment 23381 [details] Testcase for both plain Gtkmm and libglademm
I'm going to have to create a C example when I get around to this. Feel free to do that for me.
Is that attachment a tar.gz? Please mention the filename when attaching.
I've been able to work around this problem by not deriving from Gtk::OptionMenu or Gtk::MenuItem. Instead, I've used SigC::bind to call a method with an object as an argument, rather than storing the object in a derived Gtk::MenuItem. I've created a boost::lexical_cast<> workalike called template<typename T> std::string describe(const T& obj) which converts the object into a textual description for use in the optionmenu (it's specialised for each type). How exactly should I write in a C testcase for this issue, given that it only occurs when using C++ derived classes? It's as though the set_menu method behaves differently depending on wether you created the OptionMenu directly, or by libglademm get_widget_derived. The latter does have the menu (the item count is correct), but it doesn't display them. Thanks, Roger
Sorry, but this is not a simple-as-possible test case. If you provide a simple test case then I will investigate, and probably fix, any bug.
Is there any chance of us getting that test case?
What should the C testcase do? There's no libglade get_widget_derived() equivalent, so I'm unsure what exactly you want. I'll be happy to try writing another testcase--but I need to know what it should do first. Thanks, Roger
Nevermind about the C test case yet. We still don't have a simple C++ test case from you.
Created attachment 33181 [details] gtkmm-131566-2.tar.bz2 This testcase is a simplified version of the original testcase. I've - removed all the templated code - removed all unused cruft - commented the objectoptionmenu header The objectoptionmenu.* files implement the classes ObjectOptionMenuItem (derived from Gtk::MenuItem) and ObjectOptionMenu (derived from Gtk::OptionMenu). examplewindow.* is plain C++, and just creates a main window containing an ObjectOptionMenu containing some ObjectOptionMenuItems. This works perfectly. gladeexamplewindow.* is exactly the same, but the ObjectOptionMenu is got from a Glade::XML object with get_widget_derived. This appears to work according to the debugging messages (the contained Gtk::Menu does contain the correct number of items and the current selection is correct), but it shows up empty with warnings: OptionMenu::on_changed() There are 6 items Currently selected: 1 OptionMenu::on_changed() There are 6 items Currently selected: 5 (gladeexamplewindow:5036): Gtk-CRITICAL **: file gtkmenu.c: line 1235 (gtk_menu_popup): assertion `GTK_IS_MENU (menu)' failed (gladeexamplewindow:5036): Gtk-CRITICAL **: file gtkmenu.c: line 1470 (gtk_menu_get_active): assertion `GTK_IS_MENU (menu)' failed Hopefully this is a good bit simpler, but I don't think I can make it much simpler without losing the purpose of what I'm trying to do. Regards, Roger
In your constructor ObjectOptionMenu::ObjectOptionMenu(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& xml_interface): m_menu() {} You do not call the base class constructor. This is explained here: http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch19s03.html Please reopen the bug if this does not fix the problem.
Also, I suggest that you use warnings as errors. This would have caught the unused cobject parameter.
That does indeed fix the problem, thanks. I thought it looked funny, but I couldn't for the life of me see what it was--and I've written quite a few derived widgets with those constructors in. Sorry for being a such a lamer!
No problem. That's why I prod people to make test cases.