Search code examples
c++jucefilefilter

How do I describe what file filter I want using juce's FileFilter?


I'm trying to have the browser only show audio files, however, I don't know what syntax to use to describe what file type I would like

fileChooser->setFileFilter(FileFilter(".wav"));

When I put this it says "Allocating an object of abstract class type 'juce::FileFilter'"

Sorry if this is an easy one


Solution

  • You should use a WildcardFileFilter instead, since FileFilter is an abstract base class:

    fileChooser->setFileFilter(WildcardFileFilter("*.wav", "*", "somedescription"));
    

    Docs.

    Note that setFileFilter asks for a const*, meaning that you must manage it's lifetime.

    At this moment, you're passing a temporary that will be destructed leaving the fileChooser with a dangling pointer, you should use something with a longer lifetime.