我有以下問題GtkTreeView
。unicolumn 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
讓我覺得,也許它定義列數枚舉是不正確的,我tryed寫只是整數而不是枚舉值。它沒有幫助。
正如你可以看到我的debbuger結果的乞求,有什麼printf打印在屏幕上,所以數據結構record
中的值存在並且是正確的。無論如何,我試着把常量字符放在參數中,它什麼都不改變。
如果我通過null
作爲列表的參數,它只顯示一個警告,如invalid cast
等,當然它也不工作:)這只是奇怪,沒有像分段故障這樣的關鍵錯誤。
就是這樣,現在我明白了,非常感謝! – Marek