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



On Sun, 2004-08-01 at 12:35, Samuel Abels wrote:
> I have now found out that the following code...
> 
> void GtkBookList::remove_selected(void)
> {
>   Gtk::TreeIter iter = sortstore->convert_iter_to_child_iter(
>       get_selection()->get_selected());
>   if (!iter)
>     return;
>   Book* book = iter->get_value(columns.book);
>   printf("Book found: %s\n", book->get_title().c_str());
>   store->erase(iter);
> }
> 
> ...does indeed remove the correct row, but then store->erase() also
> generates error messages:
> 
> (test:10373): Gtk-CRITICAL **: file gtktreemodelsort.c: line 1055
> (gtk_tree_model_sort_get_value): assertion `GTK_TREE_MODEL_SORT
> (tree_model)->stamp == iter->stamp' failed
> 
> (test:10373): GLib-GObject-CRITICAL **: file gvalue.c: line 149
> (g_value_unset): assertion `G_IS_VALUE (value)' failed

This is finally solved: The reason is that store->erase() invokes a
selection_changed signal, which was connected to this:

void GtkBookList::on_selection_changed(void)
{
  Book* book = get_selection()->get_selected()->get_value(columns.book);
  signal_book_selected.emit(book);
}

All I had to do is to check whether something is selected here. So by
changing the callback to this:

void GtkBookList::on_selection_changed(void)
{
  Gtk::TreeIter iter = get_selection()->get_selected();
  if (!iter)
    return;
  Book* book = iter->get_value(columns.book);
  signal_book_selected.emit(book);
}

everything works just as expected. :-)

Thanks!
-Samuel
-- 
 ------------------------------------------------------
|      Samuel Abels       |   http://www.debain.org    |
| spam ad debain dod org  | knipknap ad jabber dod org |
 ------------------------------------------------------



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