Re: How to clear/replace filter list in File Chooser?
- From: Toralf Lund <toralf procaptura com>
- To: GTK-- Mailing List <gtkmm-list gnome org>
- Subject: Re: How to clear/replace filter list in File Chooser?
- Date: Wed, 14 Feb 2007 15:45:55 +0100
Toralf Lund wrote:
Does anyone here know how to clear the list of user selectable filters
from a file selector and/or replace the list with a new one? Or
differently put, can someone spot the mistake(s) in the code included below?
[ ... ]
I think I can answer that question myself, now. The problem is that the
filter is set up as a temporary object (on the stack), where it
apparently must be allocated - because add_filter() stores a reference
to it. In other words,
if(!validExtensions.empty()) {
Gtk::FileFilter extFilter;
...
add_filter(extFilter);
set_filter(extFilter);
}
}
should be changed to
if(!validExtensions.empty()) {
Gtk::FileFilter *extFilter=new Gtk::FileFilter;
...
add_filter(*extFilter);
set_filter(*extFilter);
}
}
I had somehow concluded that add_filter would copy data rather than
store a reference. Not sure why, but it seems clear now that I was wrong.
What strikes me as odd, though, is that the application wouldn't crash
right away (as the temporary Gtk::FileFilter was destroyed), but worked
just fine until it tried to remove the filters in order to set up a new
list at a much later stage.
I'm also wondering why add_filter() takes a const reference when the
FileChooser actually takes ownership of the object and may destroy it
automatically, according to the docs (I also overlooked that bit of
information earlier ;-() Seems like most adds in Gtk uses non-const
references in such cases...
- Toralf
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]