Gtk_menu_get_title was deprecated without many details, what is the correct approach?

I’m using C++ and GTK+3 stable. I’m looking for the correct way to do what the gtk_menu_get_title function did. I see a brief note that says this function has been deprecated but it doesn’t say what the preferred approach should be. Does anyone have any ideas? Thanks!

There’s no replacement because tear off menus are also deprecated. That’s the only use case for the “title” property of GtkMenu.

Im not sure what a “tear off” menu is (sorry, im new to this ecosystem), im just creating a regular old menubar at the top of the app window. When I activate a menu item, i want to get its parent menu and some details about it. This seems like a common use case. I find it easy to get the parent, but I don’t see a way to set and get arbitrary data on it. I’m willing to accept that my mental model of how all this works might not be there yet. My current solution is to pack everything i need to know into the menu item.

I mean {get,set}_data exist, but entirely sure what/why your trying to do here though?

Are you perhaps referring to gtk_object_{get,set}_data? Can those functions work on menu items? If so, that would work for me.

No, because GtkObject is loooooooooong dead - you want g_object_{get,set}_data which work on all GObjects (not particularly pretty though).

I still wonder what your trying to do here that needs arbitrary data

To restate my goal differently: let’s say that i have a dynamically created menuBar, and there are two menus in it, Apples and Oranges, both of which have a menuItem called Eat. When an Eat menuItem is activated, how do you know which one it was? One way to solve this (in pseudo code) is

You could use gtk_widget_set_name (menu, "Apples") and gtk_widget_set_name (menu, "Orange"), and then use gtk_widget_get_name(gtk_widget_get_parent (menu_item)).

You could also use two different callbacks—one for the menu item under “Apples” and one for the menu item under “Orange”; there is no worldwide shortage of functions, so there’s no real need to ration the ones you use.

I’d also like to point out that if you used GMenu and GAction to build your menus, instead of widgets, you would have different actions associated to the different “Eat” items. This would also make your menu code future proof, as GTK4 removed menu widgets and only allows creating menus through GMenuModel.


Or a single action with different targets, like and


I currently have a single action that handles everything, that’s why i needed to traverse up the hierarchy to determine the parent. I’m also using exactly the technique that @ebassi describes. I will perhaps try to learn GMenu and GAction but it seems like a big rewrite I’d like to avoid. Sounds like I’ve gotten as close to correct as i can get with this. Thanks everyone :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.