Search code examples
gtkgobject

Get the class structure instance of a GObject type


How do I get a class object of a certain class in GObject / Gtk? For example, if my class is GtkSpinButton, I want to get the instance of GtkSpinButtonClass that represents the class. It is the parameter "class" in

gtk_spin_button_class_init (GtkSpinButtonClass *class)

and it is the object where virtual functions are stored. When I have an instance of GtkSpinButton, I can call

GtkSpinButtonClass *class = GTK_SPIN_BUTTON_GET_CLASS (instance)

however I don't have an instance around. GTK_TYPE_SPIN_BUTTON gives me the type id, a number, and not the class object. Any idea how to get the actual instance?


Solution

  • You want to use g_type_class_ref

    GtkSpinButtonClass *klass = g_type_class_ref(GTK_TYPE_SPIN_BUTTON);
    

    and when you're done with it

    g_type_class_unref(klass);