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()) {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.Gtk::FileFilter *extFilter=new Gtk::FileFilter;... add_filter(*extFilter); set_filter(*extFilter);} }
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