Is it possible to add private data to a GtkWidget
?
Background:
I have many GtkCheckBotton
s, all these widgets are connected to the same callback. In the callback, I would like to handle the widgets private data (or at least distinguish between the widgets).
Example:
// checkbox signal callback
void on_checkbox_tcoggled(GtkWidget* widget, gpointer data) {
MyClass* me = data;
MyPrivateData* priv = widget->priv; // ???
MyClass_foo(me, priv);
}
Is it possible to add private data to a GtkWidget?
You can use functions g_object_set_data
and g_object_get_data
to add arbitrary data to any GObject
.
MyPrivateData *priv = ...
g_object_set_data(G_OBJECT(widget), "my private data", priv);
// ...
void on_checkbox1_toggled(GtkWidget* widget, gpointer data) {
MyClass* me = data;
MyPrivateData* priv = (MyPrivateData*) g_object_get_data(G_OBJECT(widget), "my private data");
MyClass_foo(me, priv);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With