|Error|C2248|‘juce::String::operator bool’: cannot access private member declared in class ‘juce::String’
This is the offending bit of code
void PlaylistComponent::buttonClicked(Button* button) {
int id = std::stoi(button->getComponentID().toStdString());
DBG("ID = " + id);
DBG("Track Title = " + trackTitles[id]);
//load file stuff for "Add Song" button
if (button->getButtonText() == "Add Song") {
FileChooser chooser{ "Select a file..." };
String newTitle = chooser.getResult().getFileNameWithoutExtension();
if (chooser.browseForFileToOpen())
{
DBG(chooser.getResult().getFileNameWithoutExtension());
trackTitles[id] = newTitle;
DBG(trackTitles[id]);
}
}
};
I no matter what I do, I can’t seem to change the value of trackTitles[id] to the file-names
What kind of container is trackTitles
? Which line is the bug?
leehu
May 8, 2022, 10:47am
3
FYI, you can replace the first line with:
const auto id = button->getComponentID().getIntValue();
to save having to do the conversion.
1 Like
You’re reading the result of the file chooser before actually opening it:
String newTitle = chooser.getResult().getFileNameWithoutExtension();
if (chooser.browseForFileToOpen())
{
}
You probably want to get the result after the user has chosen a file:
if (chooser.browseForFileToOpen())
{
trackTitles[id] = chooser.getResult().getFileNameWithoutExtension();
}
1 Like
It’s a vector array with the following declaration
std::vector<std::string> trackTitles;
The error comes up on the line trackTitles[id] = newTitle;
Try using newTitle.toStdString
1 Like
Sadly, the error still occurs even with this adjustment
Thank you! This worked perfect
1 Like
That wasn’t supposed to fix your compilation error. This was a hint on why your program will not work at runtime
2 Likes
You try to assign a juce::String
to a std::string
.
Your message error is probably due to some weird conversion your compiler is trying to do.
You can use juce::String::toStdString .
Oops didn’t see the @Rincewind response.
2 Likes
Why are you using a mix of juce::String
s and std::string
s OOI?
I’d recommended just sticking to juce::String
throughout your project, unless there’s something you specifically need from std::string
.
You could also use juce::StringArray
rather than std::vector<juce::String>
, which has a few nifty features.