Re: [gtkmm] multiple selections on TreeView

Am Fre, 2002-11-22 um 20.54 schrieb Frank Naumann:
> Hello!
> I have a question about multiple selections on a TreeView under
> gtkmm 2.0.1.


> The problem is now that if I try to remove something at runtime I
> get the following error message on stderr:
> (main.exe:10569): Gtk-CRITICAL **: file gtktreeselection.c: line 491
> (gtk_tree_selection_selected_foreach): assertion `has_next' failed.
> There is a disparity between the internal view of the GtkTreeView,
> and the GtkTreeModel.  This generally means that the model has changed
> without letting the view know.  Any display from now on is likely to
> be incorrect.
> For me it looks like I can't call erase in on_remove_selection() as this
> possible invalidates the iterator. If this is true is there any other way
> to remove multiple selections? Or I'm tottaly wrong here?

Yes, that's right.  It's a limitation of the underlying GTK+ interface. 
You have to do something along these lines:

    typedef std::list<Gtk::TreeModel::Path> PathList;

    // static
    void Foo::collect_path(const Gtk::TreeModel::Path& path, PathList* path_list)

    void Foo::remove_selected()
      PathList path_list;

          SigC::bind(SigC::slot(&Foo::collect_path), &path_list));

      for(PathList::iterator p = path_list.begin(); p != path_list.end(); ++p)

Theorhetically you could even avoid collect_path() by connecting to
PathList::push_back() directly, but that would require usage of
SigC::slot_class() which only few people seem to be familiar with :)


P.S.: collect_path() of course doesn't have to be static, but it
simplifies this example a bit since it eliminates the need for an object

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