【发布时间】:2019-02-11 18:22:04
【问题描述】:
我正在制作一个 GTK3 应用程序,并在 GtkListBoxRow 上使用 g_object_set_qdata 进行搜索。
我使用这个代码:
GArray *complib;
#define row_get_entry(row) (ElcCompLibEntry*)g_object_get_qdata(G_OBJECT(row),registryquark)
GtkWidget* elc_registry_listbox_make_item(ElcCompLibEntry* curritem)
{
/* I remove UI creation */
GtkWidget* intermediate = gtk_list_box_row_new();
gtk_container_add(GTK_CONTAINER(intermediate),GTK_WIDGET(mainbox));
gtk_widget_show_all(GTK_WIDGET(intermediate));
g_object_set_qdata(G_OBJECT(intermediate),registryquark,curritem);
return intermediate;
};
static GtkWidget* saved = NULL;
GtkWidget* new=elc_registry_listbox_make_item(entry);
gtk_container_add(GTK_CONTAINER(listbox->real_listbox),new);
if (saved)
g_debug("saved entry is at position %d",((gintptr)row_get_entry(saved)-(gintptr)complib->data)/sizeof(ElcCompLibEntry));
saved=new;
g_debug("entry is at position %d",((gintptr)row_get_entry(new)-(gintptr)complib->data)/sizeof(ElcCompLibEntry));
我的程序的输出:
** (elc:9906): DEBUG: 18:51:10.623: entry is at position 0
** (elc:9906): DEBUG: 18:51:10.625: saved entry is at position -14015
** (elc:9906): DEBUG: 18:51:10.625: entry is at position 1
** (elc:9906): DEBUG: 18:51:10.627: saved entry is at position 32
** (elc:9906): DEBUG: 18:51:10.627: entry is at position 2
** (elc:9906): DEBUG: 18:51:10.629: saved entry is at position 2
** (elc:9906): DEBUG: 18:51:10.629: entry is at position 3
** (elc:9906): DEBUG: 18:51:10.631: saved entry is at position 25921
** (elc:9906): DEBUG: 18:51:10.631: entry is at position 4
ElcCompLibEntry 是一个简单的结构。
g_object_set_qdata_full 只是破坏了旧数据,夸克被初始化,即使在主线程中运行它我也得到了相同的结果(只有 saved entry is at position 2 是恒定的)。
有人可以帮助找到问题的根源和/或将我发送到相关文档吗?
感谢您的宝贵时间!
【问题讨论】: