TL; DR: assertion 'VALID_ITER (parent, tree_store)' failed
。我该如何解决?
我已经在我的应用程序中使用以下(修剪过的)代码成功显示了一个GtkTreeView:
enum { DISPLAY_COLUMN, N_COLUMNS };
GValue comment = G_VALUE_INIT;
GValue amount = G_VALUE_INIT;
GtkTreeIter toplevel, child;
GtkTreeStore *treestore = gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING);
for(int step = 0; step < recipe_count; step++) {
g_value_init(&comment, G_TYPE_STRING);
g_value_set_string(&comment, recipe[step].comment);
gtk_tree_store_append(treestore, &toplevel, NULL);
gtk_tree_store_set_value(treestore, &toplevel,
COMMENT_COLUMN, &comment
);
g_value_init(&amount, G_TYPE_STRING);
g_value_set_string(&amount, recipe[step].amount);
gtk_tree_store_append(treestore, &toplevel, &child);
gtk_tree_store_set_value(treestore, &toplevel,
COMMENT_COLUMN, &amount
);
g_value_unset(&amount);
g_value_unset(&comment);
}
gtk_tree_view_set_model(GTK_TREE_VIEW(app->step_tree),GTK_TREE_MODEL(treestore));
GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ("Step",
renderer,
"text", DISPLAY_COLUMN,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(app->step_tree), column);
以上所有内容都包含在一个函数中,以便我以后可以再次加载新数据。但是,我第二次尝试
(recipe_editor:11451): Gtk-CRITICAL **: IA__gtk_tree_store_append: assertion `VALID_ITER (parent, tree_store)' failed
(recipe_editor:11451): Gtk-CRITICAL **: IA__gtk_tree_store_set_value: assertion `VALID_ITER (iter, tree_store)' failed
我知道这意味着我的迭代器有问题,但我不确定如何实际修复它。