Re: Do TreeIters persist after foreach search ?



Torsten Schoenfeld wrote:
On Thu, 2007-11-08 at 11:53 +0000, Dave Howorth wrote:

I think there must be something I'm overlooking about iters. I have code
which for testing I've simplified to the following:

What works for me in Odot is storing a copy of the iterator:
...
              $match_iter = $iter->copy;

Thanks, Torsten. I've just checked with my test program and it works for
me too. I'm rewriting another way to get more efficiency, but I'll
remember about Glib::Boxed->copy now you've introduced me to it!


I've also noticed that there is some specific Gtk2-Perl documentation
about iterators in the Gtk2::TreeModel description. I think the text is
misleading as well as incomplete, especially since it differs from the
underlying gtk+ functionality. So I'd suggest a change. Presently it says:

" ... These iterators are the primary way of accessing a model and are
similar to the iterators used by Gtk2::TextBuffer. They are generally
used only for a short time, and are valid only as long as the model is
unchanged. The model interface defines a set of operations using them
for navigating the model."

How about something like:

" ... These iterators are the primary way of accessing a model and are
similar to the iterators used by Gtk2::TextBuffer. The model interface
defines a set of operations using them for navigating the model.

The iterators are generally used only for a short time, and their
behaviour is different to that suggested by the Gtk+ documentation. They
are not valid when the model is changed, even though get_flags returns
'iters-persist'. Iterators obtained within a GtkTreeModelForeachFunc are
also invalid after the foreach terminates. There may be other such
cases. In the foreach case, and perhaps others, a persistent iterator
may be obtained by copying it (see Glib::Boxed->copy)"

Sorry it's not very elegant but I don't know enough to be definitive!

Cheers, Dave



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