Number of arguments in the gcallback function, and how to find out the name of an argument type


I want to create a menu with a group of radio menu items with the help of gtk_action_group_add_radio_actions as shown in the GnomeUIInfo migration guide.

gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
                                    const GtkRadioActionEntry *entries,
                                    guint n_entries,
                                    gint value,
                                    GCallback on_change,
                                    gpointer user_data);

It took long to find out that the callback function takes three arguments instead of two. Up to now I only saw that a gcallback function uses two arguments. But here the user data is received as the third argument:

void on_change(GtkAction *action, GtkRadioAction *item, gpointer *user_data) {...} 

I realized this in the testmerge.c example in the gtk sources. There was no other hint, also not in the documentation.

To this I have two questions:

  1. How could I have find out that the callback function has three instead of two arguments when I want to use the user data? Is there a way to find this out?
  2. I actually expected the user data to be passed on the second argument position. In this case it should have been of type “GVIEWER_WINDOW”. I realized that this was not the case by checking the type with IS_GVIEWER_WINDOW (user_data). But how could I have find out that the seconde argument is of type GTK_RADIO_ACTION? Is there a method to get the name of a pointer type? If yes, how is that done?

Thank you in advance

It is in the documentation, albeit not in the most obvious way:

The “changed” signal of the first radio action is connected to the on_change callback

The documentation of the GtkRadioAction::changed signal then gives you the signature of the handler:

user_function (GtkRadioAction *action,
               GtkRadioAction *current,
               gpointer        user_data)

Oh, wow. Thank you. Yea, I could have seen that, but a direct link in the documentation to this place would have been helpfull. :sweat_smile:

Any idea to my other two questions, anyone? :wink:

Consult the documentation.

The first and last parameter are always the instance that emits the signal and the user_data pointer that was specified when connecting the handler(*), but as you learned signals can have additional parameters.

(*) usually in that order unless the G_CONNECT_SWAPPED flag was used, in which case they switch places

There is no method for getting the name of an arbitrary pointer type, but you can find out the types of the additional signal parameters:

  GSignalQuery query;
  guint i;

  g_type_class_ref (GTK_TYPE_RADIO_ACTION);
  g_signal_query (g_signal_lookup ("changed", GTK_TYPE_RADIO_ACTION), &query);

  g_print ("[0]: %s\n", g_type_name (query.itype));
  for (i = 0; i < query.n_params; i++)
    g_print ("[%d]: %s\n", i + 1, g_type_name (query.param_types[i]));
  g_print ("[%d]: gpointer\n", i + 1);

But then consulting the documentation is generally faster, and hopefully also tell you what those parameters mean :wink:


Thank you, Florian. That’s the explanation I was looking for.

Have a nice weekend!

That is really interesting. It may be useful for language bindings creation, its a way to find out signal parameter types without direct gobject-introspection use.

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