Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add private data to a GtkWidget?

Tags:

c

gtk

gtk2

Is it possible to add private data to a GtkWidget?

Background:

I have many GtkCheckBottons, 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);
}
like image 583
sergej Avatar asked Mar 12 '23 16:03

sergej


1 Answers

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);
}
like image 166
el.pescado - нет войне Avatar answered Mar 25 '23 10:03

el.pescado - нет войне