我有以下问题GtkTreeView
。
当我尝试附加列表时会出现问题。这是我创建的函数:
static GtkWidget *setup_list_archive(GtkWidget **widget)
{
GtkWidget *sc_win;
GtkListStore *store;
GtkCellRenderer *cell;
GtkTreeViewColumn *column;
sc_win = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_usize(sc_win, 250, 150);
store = gtk_list_store_new(COL, G_TYPE_STRING, G_TYPE_STRING);
*widget = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
cell = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Klucz", cell, "text", ID, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(*widget), column);
cell = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Data", cell, "text", DATA, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(*widget), column);
cell = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Godzina", cell, "text", CZAS, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(*widget), column);
// scrolls behavior
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sc_win), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(sc_win), *widget);
// free the objects
g_object_unref(G_OBJECT(store));
return sc_win;
}
这是我附加列表的函数。
static void list_add_archive(GtkWidget* widget, gpointer data)
{
arch *rekord = (arch*) data;
printf("key: %s; pas: %s; dat: %s;\n", rekord->id, rekord->czas, rekord->data);
GtkListStore *store;
GtkTreeIter iter;
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget)));
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, ID, rekord->id, DATA, rekord->czas, CZAS, rekord->data, -1);
}
only
多列类型的列表会出现问题。如果我用一个列创建列表,它工作正常。
这是我的回溯。
key: 1; pas: 14; dat: 2013-06-22 12:24:58;
Breakpoint 1, list_add_archive (widget=0x80e0c40, data=0xbfffe704)
at admin.c:512
512 gtk_list_store_append(store, &iter);
(gdb) step
513 gtk_list_store_set(store, &iter, ID, "a", DATA, "b", CZAS, "c", -1);
(gdb) step
Program received signal SIGSEGV, Segmentation fault.
0xb76b8ff5 in g_type_value_table_peek ()
from /usr/lib/i386-linux-gnu/libgobject-2.0.so.0
(gdb) step
Single stepping until exit from function g_type_value_table_peek,
which has no line number information.
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) step
The program is not being run.
这行g_type_value_table_peek, which has no line number information
让我觉得定义列号的枚举可能不正确,我试图只写整数而不是枚举值。它没有帮助。
正如您在我的调试器结果的乞求中看到的那样,printf 打印在屏幕上,因此数据结构中的值record
存在并且是正确的。无论如何,我尝试将 const chars 放入参数中,但它什么也没改变。
如果我作为列表的参数传递null
,它只显示一个警告,比如invalid cast
等等,当然它也不起作用:) 奇怪的是没有像分段错误这样的严重错误。