I Created a window and vbox with 3 buttons in Glade. All buttons have connected “Clicked” event to same handler. Handler looks like this:
CLICKED_btn(GtkObject *object, gpointer user_data)
{
g_print("CLICKED\n");
}
CLICKED appears on terminal for any click to any button.
Is here a way, through object or other to know which button invokes event Clicked in case where all buttons uses same handler?
The
objectparameter refers to the object that generates the event, in your case the button. Then you can usegtk_widget_get_name()or any other GtkObject/GtkWidget/GtkButton function to make a difference.UPDATE:
As it seems, newer versions of GTK/Glade do not set the name of the widgets to their
id, so it is left to the default, that is the name of the type. In order to get theidof the object you can use the functiongtk_buildable_get_name()that works with any buildable object.With that you’ll get
button1,button2or whatever name you put to these buttons.Please, do not use the label to make a difference between the buttons. Yes, it works, but it is a bad habit: hard to maintain, bad with internationalization, and defeats the main purpose of Glade: to have the interface and the code separated.