Append a node to the top level in a GetkTreeStore



Reading the docs of  gtk_tree_store_append ():

"Appends a new row to /|tree_store|/. If /|parent|/ is non-|NULL|, then it will append the new row after the last child of /|parent|/, otherwise it will append a row to the top level. /|iter|/ will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call |gtk_tree_store_set()| <http://localhost.localdomain/cgi-bin/dwww?type=file&location=/usr/share/doc/libgtk2.0-doc/gtk/GtkTreeStore.html#gtk-tree-store-set> or |gtk_tree_store_set_value()| <http://localhost.localdomain/cgi-bin/dwww?type=file&location=/usr/share/doc/libgtk2.0-doc/gtk/GtkTreeStore.html#gtk-tree-store-set-value>."

Now, if I try the to insert two node at the top level in the same body procedure, all work as expected: the program create two nodes at the top level.

But if I call two times the same procedure to update the GtkTreeStore, the result is not, as expected (at least for me), four node at the top level, but only two, the last that the procedure insert the second time was called.

Here is a slice of the program I made to test:

...
add_istruction(istr); //called two times
...


void add_instruction(char *istr) {
...

gtk_tree_store_append (GTK_TREE_STORE(store), &iter, NULL); /* Acquire an iterator */ gtk_tree_store_set (GTK_TREE_STORE(store), &iter,
                           N_ISTRUCTION_COLUMN, istr,
                           CONDITION_COLUMN, "",
                           ISTRUCTION_COLUMN, istr,
                           GOTO_COLUMN, "",
                           -1);
gtk_tree_store_append (GTK_TREE_STORE(store), &iter, NULL); /* Acquire an iterator */ gtk_tree_store_set (GTK_TREE_STORE(store), &iter,
                           N_ISTRUCTION_COLUMN, istr,
                           CONDITION_COLUMN, "",
                           ISTRUCTION_COLUMN, istr,
                           GOTO_COLUMN, "",
                           -1);

...

The fist time istr == "BEGIN", while the second is equal to "STOP". At the end, the treeview contain only two top nodes labeled "STOP".

Does someone understand why?

Thanks in advance for any advice.

ciao, Michele




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]