I made a treeview with a treestore as model. The window is shown as expected, but when I click in the "+" to expand the items, I get this message:
GLib-CRITICAL **: Source ID 221 was not found when attempting to remove it
Here is my code:
#include <gtk/gtk.h>
/* compile with: */
/* gcc main.c -o boxy `pkg-config --cflags --libs gtk+-2.0` */
typedef struct {
GtkWidget *toplevel;
GtkWidget *treeview;
} Widgets;
enum { ITEM_PARENT, ITEM_CHILD };
typedef struct {
gint tipo;
gint id;
gchar *nombre;
gint cantidad;
} Lista;
void addColumn (GtkTreeView *tv, const gchar* title, gint pos) {
GtkCellRenderer *tmp;
tmp = gtk_cell_renderer_text_new ();
g_object_set (tmp, "editable", TRUE, "editable-set", TRUE, NULL);
gtk_tree_view_insert_column_with_attributes (tv, -1, title, tmp, "text", pos, NULL);
}
void setupTree (GtkTreeView *tv) {
const Lista lista[] = {
{ITEM_PARENT, 125, "Superman", 2},
{ITEM_CHILD, 23, "Batman", 1},
{ITEM_CHILD, 7, "Hulk", 5},
{ITEM_PARENT, 65, "Iron Man", 2},
{-1, -1, NULL, -1}
};
GtkTreeStore *model;
GtkTreeIter last;
gint pos;
model = gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT);
addColumn (tv, "ID", 0);
addColumn (tv, "Nombre", 1);
addColumn (tv, "Cantidad", 2);
for (pos = 0; lista[pos].tipo != -1; pos++) {
GtkTreeIter iter;
if (lista[pos].tipo == ITEM_PARENT) {
gtk_tree_store_append (model, &iter, NULL);
last = iter;
} else if (lista[pos].tipo == ITEM_CHILD) {
gtk_tree_store_append (model, &iter, &last);
}
gtk_tree_store_set (model, &iter, 0, lista[pos].id, 1, lista[pos].nombre, 2, lista[pos].cantidad, -1);
}
gtk_tree_view_set_model (tv, GTK_TREE_MODEL (model));
g_object_unref (model);
}
int main (int argc, char *argv[]) {
Widgets *ptr;
GtkWidget *scroll;
gtk_init (&argc, &argv);
ptr = g_slice_new0(Widgets);
ptr->toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL);
scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_OUT);
ptr->treeview = gtk_tree_view_new ();
setupTree (GTK_TREE_VIEW (ptr->treeview));
g_signal_connect (ptr->toplevel, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_set_border_width (GTK_CONTAINER (ptr->toplevel), 10);
gtk_container_add (GTK_CONTAINER (scroll), ptr->treeview);
gtk_container_add (GTK_CONTAINER (ptr->toplevel), scroll);
gtk_widget_show_all (ptr->toplevel);
gtk_main ();
g_slice_free (Widgets, ptr);
return 0;
}
Any ideas?
See Question&Answers more detail:
os