Deleting rows from a model

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Deleting rows from a model

Gtk+ - Perl mailing list
Hi all. I've been looking at a long-standing bug in one of my libraries, triggered when I delete multiple rows from a tree model. After looking closer, my original bug appears to be caused by the fact that after going:

$model->remove( $iter );

 ... $iter is now pointing at the *next* row, without me having to go:

$model->iter_next( $iter );

So this initially seemed to be easy to solve - just don't call iter_next() if I've deleted a row. But ... I was previously exiting the loop, based on the return of $model->iter_next( $iter ). If there are no more rows, this call returns false. Since I'm not calling it for deleted rows, and since $iter is still 'set' in this case, how do I know if I'm at the end of the model?

Currently in this situation, my loop exits anyway, but due to:

(main.pl:7769): Gtk-CRITICAL **: 20:49:43.945: gtk_list_store_get_value: assertion 'iter_is_valid (iter, list_store)' failed

(main.pl:7769): Gtk-CRITICAL **: 20:49:55.529: gtk_list_store_get_value: assertion 'iter_is_valid (iter, list_store)' failed
*** unhandled exception in callback:
***   [gperl_sv_from_value] FIXME: unhandled type - 0 ((null) fundamental for (null))
***  ignoring at /usr/local/lib64/perl5/5.24.1/Gtk3.pm line 546.

 ... which I guess is because, as the error says, $iter is not valid. Is there an iter_is_valid() method or something?

Thanks :)

Dan

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Deleting rows from a model

Gtk+ - Perl mailing list
On Thu, 13 Sep 2018 at 12:01, Daniel Kasak via gtk-perl-list <[hidden email]> wrote:
Hi all. I've been looking at a long-standing bug in one of my libraries, triggered when I delete multiple rows from a tree model. After looking closer, my original bug appears to be caused by the fact that after going:

$model->remove( $iter );

 ... $iter is now pointing at the *next* row, without me having to go:

$model->iter_next( $iter );


Just like the documentation[0] for gtk_list_store_remove() says.
 
So this initially seemed to be easy to solve - just don't call iter_next() if I've deleted a row. But ... I was previously exiting the loop, based on the return of $model->iter_next( $iter ). If there are no more rows, this call returns false. Since I'm not calling it for deleted rows, and since $iter is still 'set' in this case, how do I know if I'm at the end of the model?

Use the return value of `Gtk::ListStore::remove()` to see if the iterator is still valid or not.

Ciao,

--

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list