我已经解决了信号连接中的先前问题,但在另一个问题上我感到困惑。我在Glade中创建了一个树视图,当我在Glade的list_store中操作数据时,它成功了。但是,当我想通过编码添加数据时,我失败了。以下是主要代码。如果你能帮助我,我将非常感激。
#include "gtk/gtk.h"
typedef struct _MainDate{
GtkWidget *main_window;
GtkWidget *delete_button;
GtkWidget *choose_button;
GtkListStore *liststore_1;
GtkTreeViewColumn *name;
GtkTreeViewColumn *phone;
GtkTreeView *view;
}MainDate;
int main(int argc,char *argv[]){
GtkBuilder *builder;
GtkTreeIter iter;
MainDate *date;
GError *error = NULL;
gtk_init(&argc,&argv);
builder = gtk_builder_new();
if(!(gtk_builder_add_from_file(builder,"main_window.glade",&error))){
g_warning("%s",error->message);
g_free(error);
return 1;
}
date = g_slice_new(MainDate);
date->main_window = GTK_WIDGET(gtk_builder_get_object(builder,"main_window"));
date->liststore_1 = GTK_LIST_STORE(gtk_builder_get_object(builder,"main_window"));
date->name = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"name"));
date->phone = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,"phone"));
gtk_list_store_append(date->liststore_1,&iter);
gtk_list_store_set(date->liststore_1,&iter,date->name,"陈婷婷",date->phone,"18202731442",-1);
gtk_builder_connect_signals(builder,date);
g_object_unref(builder);
gtk_widget_show_all(date->main_window);
gtk_main();
g_slice_free(MainDate,date);
return 0;
}
答案 0 :(得分:1)
您正在将指向GtkTreeViewColumn的指针传递给gtk_list_store_set()
。这是错的;它应该是列数字,0是第一列。因此,例如,如果name列是第0列而phone列是第1列,那么该行应该是
gtk_list_store_set(date->liststore_1,&iter,0,"陈婷婷",1,"18202731442",-1);