No member named 'browseForFileToOpen' in 'juce::FileChooser'

Hi all, I’m struggling to work out my issue here, here’s the error I’m getting: No member named ‘browseForFileToOpen’ in ‘juce::FileChooser’

I’ve seen a solution online is to change a setting in the pre processor definition but I’m unsure on how to do this? Any help is greatly appreciated. Cheers

you find all the preprocessor defines in the projucer. in your project go to the place with all the juce modules and click on them to be shown their settings. one of them will be this enable modal loops thingie, but idk where exactly from the top of my head

If you want to enable features that make use of modal loops, you need to add JUCE_MODAL_LOOPS_PERMITTED=1 to your exporter’s ‘Extra Preprocessor Definitions’ entry.

However, not all platforms support modal loops, it’s recommended to use the async methods where possible.

Contains an up to date example of how to use the FileChooser class.

@oli1, thanks for the tip. I’m trying to follow the FileChooser.launchAsync example in the documentation that you point to. When my code executes FileChooser.launchAsync, I think I can see the file chooser window for an instant, but then it immediately winks out of existence. So there may be an extra step or two that I’m missing. Can you help me out with this please?

I expect it’s a threading issue of some kind. When I click the Browse button to launch the file chooser, a message like this is sent to output:

The thread 0x4878 has exited with code 0 (0x0).

Here’s my code so far. It’s very similar to the example:

void SettingsComponent::browseButtonClicked() const {
  const auto fileChooser = std::make_unique<FileChooser>(
    "Choose the executable",
    "*.exe", false);
  constexpr auto fileChooserFlags =
    FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles;
  fileChooser->launchAsync(fileChooserFlags, [this](const FileChooser& chooser) {
    const File chosenFile(chooser.getResult());

Your fileChooser is owned inside the function that returns immediately.
That means the chooser is destroyed right after it was displayed.

Thanks, @daniel. That fixed the problem.

Cool, glad it works