----- Original Message ---- From: Carlos Pereira <[EMAIL PROTECTED]> Cc: gtk-app-devel-list@gnome.org Sent: Sunday, April 27, 2008 12:10:27 PM Subject: inserting model in a GtkTreeStore
Hi all! To insert the various nodes in a GtkTreeStore, the code below works for me. The problem is, this should not work, because I am handling a GtkTreeIter as if it was some sort of integer, while it is in fact a structure! The current child node is the next parent node, so I would expect the proper way to do this would be to copy the current node iter to the parent iter, and because these are structures, I would have to copy their contents... What is the standard way of doing this? I am confused! Thanks! Carlos GtkTreeIter insert_row (GtkTreeStore *store, GtkTreeIter *parent, char *label) { GtkTreeIter iter; gtk_tree_store_append (store, &iter, parent); gtk_tree_store_set (store, &iter, 0, label, -1); return iter; } void insert_model (GtkWidget *treeview) { GtkTreeStore *store; GtkTreeIter iter1, iter2, iter3; store = gtk_tree_store_new (1, G_TYPE_STRING); iter1 = insert_row (store, NULL, "Node 0"); iter2 = insert_row (store, &iter1, "Node 0:0"); insert_row (store, &iter2, "Node 0:0:0"); insert_row (store, &iter2, "Node 0:0:1"); gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store)); g_object_unref (store); } ------------------------------------------- I believe this is copying the struct (which is allowed as of c99 or something, I believe). Now, if you leave the function and try to use one of the copied structs, it probably won't work, becuase these iters were allocated on the stack, and will have been freed. You can do that only if you only will use the iter in the current function, otherwise you'll want to use it as a pointer instead. ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list