Skip to content

Instantly share code, notes, and snippets.

@mjakeman
Created January 14, 2022 16:38
Show Gist options
  • Save mjakeman/40df639f107755b83c7cb62b12be8da1 to your computer and use it in GitHub Desktop.
Save mjakeman/40df639f107755b83c7cb62b12be8da1 to your computer and use it in GitHub Desktop.
A quick snippet for listing all the properties and signals of a GObject. Something I've ended up using far more often than you would think.
// We have an object of type MyObject called 'obj'
// To use:
// replace 'obj' with your var name
// replace 'MY_TYPE_OBJECT' with the object's gtype
// snip
guint n_props;
GParamSpec **params = g_object_class_list_properties (G_OBJECT_GET_CLASS (obj), &n_props);
for (guint i = 0; i < n_props; i++)
{
GParamSpec *spec = params[i];
g_print ("%s\n", g_param_spec_get_name (spec));
}
guint n_ids;
guint *ids = g_signal_list_ids (MY_TYPE_OBJECT, &n_ids);
for (guint i = 0; i < n_ids; i++)
{
guint id = ids[i];
g_print ("%s\n", g_signal_name (id));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment