Re: [gtkmm] ListStore sorting and Gtk::TreeIter validity problems



On Sunday 01 August 2004 00:09, Samuel Abels wrote:

[snip]

> I have been assuming that they remain valid for C++, because the GTK API
> docs state that the List- and TreeModel iterators remain valid, but that
> may be incorrect for C++:
>
> "Additionally, some models guarantee that an iterator is valid for as
> long as the node it refers to is valid (most notably the GtkTreeStore
> and GtkListStore)."
>
> http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeModel.html
>
> I will try this with the mentioned Gtk::TreeRowReference, I did not know
> that one.
> Either way...
>
> > Your GtkBookList::remove_book() method is therefore likely to fail.  Have
> > you mis-diagnosed the method in which the problem shows up?
>
> ...the iterators are not accessed in the test case. I have now removed
> the unnecessary methods and the map (updated files & test case
> appended), but the problem still persists.
>
> Any further ideas?

None, I am afraid.  I have used similar code to yours and it has (and does) 
work.  For efficiency reasons I would normally only call 
get_selection()->get_selected() once in any one method, by assigning it to an 
iterator, but that shouldn't make any difference.  I would also generally 
contain, rather than derive from, a Gtk::TreeView object for your purposes, 
as otherwise it is easy to confuse the model with the view (you have a tree 
view containing the tree model (a Gtk::ListStore object)), but again that 
should not really make any difference.

As regards the validity of Gtk::TreeIter, I have read that comment also but I 
have never felt confident enough to rely on it.  It is counter-intuitive to 
anyone who has used STL containers to think that you can delete an object in 
the container and still expect all other iterators referencing objects in the 
container to remain valid (particularly objects later in the sequence for 
sequential containers).

Chris.



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