无法将用户数据结构传递给 GTK 回调

Unable to Pass a Structure of User Data to GTK Callbacks

虽然关于这种情况的类似问题已经得到解答,但我还是卡住了。

我正在使用结构将数据传递给 GTK 回调。结构定义为

typedef struct List_Stores {
    GSList * list_store_master; 
    GSList * list_store_temporary; 
    List_Builder_Struct * list_builder_struct; 
} List_Store_Struct;

我在函数中声明结构。

List_Store_Struct list_store_struct;

此结构通过引用传递给在框中制作按钮的函数。

GtkWidget *accounts_buttons_hbox = make_buttons(&list_store_struct);

make_buttons内部我使用

连接信号
g_signal_connect(button, "clicked", G_CALLBACK(revert), list_store_struct);

函数内部revert我想检查结构的内容。

static void revert(GtkWidget* widget, gpointer data) {
    List_Store_Struct* list_store_struct = (List_Store_Struct *) data;

    /* The following lines point to nothing or give the debugger message Cannot access memory at address 0xblahblah */
    GtkListStore * list_store = (list_store_struct->list_builder_struct)->list_store;
    GSList * list_store_master = list_store_struct->list_store_master;
    GSList * list_store_temporary = list_store_struct->list_store_temporary; 
}

调试器显示指针list_store_struct指向空内存位置;我无法访问该结构的成员。此外,尝试访问结构的成员会导致分段错误。

将此结构传递给回调以便我可以访问该结构的成员的正确方法是什么?

正如我原来的 post 中所述,我试图将指向用户定义结构的指针传递给回调函数 List_Store_Struct。尽我所能,回调无法正确地将传递的 gpointer 转换为指向 List_Store_Struct.

的指针

后来才知道GTK提供了一个类型GPtrArray。虽然可能不是为我的用例设计的,但将 void 指针传递给 GPtrArray 的实例会在回调中完全转换,并且我能够访问辅助指针位置的数据。