Re: liststore issue 1 - iter points to wrong row after sort of column with cellrenderercombo



Hello,
after you sort the model, you shall consider that all iter and path
previously stored are wrong :
A path is a representation of the position of the row in the current case
(which you can read by using gtk_tree_path_to_string).
https://developer.gnome.org/gtk3/stable/GtkTreeModel.html#gtk-tree-path-to-string

 Iter are quite the same (but link to a particular GtkTreeModel), such as
list::iterator of C++ STL : they are pointer to row that you can use to
access to data or walk through the models.  You can make an iter from a
path and a model :

GtkTreePath *path;GtkTreeIter iter;

GtkTreeModel* model;

GtkListStore store = gtk_list_store_new(3, G_TYPE_INT,
G_TYPE_STRING,G_TYPE_STRING)

model = GTK_TREE_MODEL(store);

path = gtk_tree_path_new_from_string
<https://developer.gnome.org/gtk3/stable/GtkTreeModel.html#gtk-tree-path-new-from-string>
("3"); // third rowgtk_tree_model_get_iter
<https://developer.gnome.org/gtk3/stable/GtkTreeModel.html#gtk-tree-model-get-iter>
(model, &iter, path); // may be invalid (check return value)

 If you really want to keep track of a particular row, you have to use
GtkTreeRowReference
https://developer.gnome.org/gtk3/stable/GtkTreeModel.html#GtkTreeRowReference
But GTK will have to keep the reference up to date, so each time your
model change (inserting, deleting, sorting...)
GTK will triggered signal to update your GtkTreeRowReference which may
cause an overhead in your application

Hope this helps you to understand better the GtkTreeModel paradigm


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