How do I pass multiple variables as data with gtk signals

后端 未结 3 1910
再見小時候
再見小時候 2021-02-14 02:01

I have a small program where a gtk signal callback function needs 2 or 3 variables.

I don\'t want to make these global variables (The entire goal of the project is to be

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 02:28

    You can use g_object_set_data() and g_object_get_data(). First, set the data:

    g_object_set_data(G_OBJECT(my_edit), "my_label", my_label);
    g_object_set_data(G_OBJECT(my_edit), "age", GINT_TO_POINTER(age));
    

    and in the callback you can get the data like so:

    gint age = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "age"));
    GtkWidget *my_label = g_object_get_data(G_OBJECT(widget), "my_label");
    

提交回复
热议问题