Frage

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?

War es hilfreich?

Lösung

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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top