Problem using getText() method


#1

I’m trying to use the getText() method on a Text Editor object to get the text inputted in the Text Editor field back, however when I try to run the program in VS it throws out an error:
Error C2248 ‘juce::String::operator bool’: cannot access private member declared in class
I’m thinking it might do with the fact that I declare the text editors in the private field, but if I don’t do that it throws and undeclared field error.
Any idea why how to get the contents of the text editor?

Thanks


#2

That means you’re trying to access a private member in a derived class. We’d have to see some code.

Rail


#3

MainContentComponent()
: state (Stopped),
//--------------------
//…
//…
//-----------------
{

    setLookAndFeel (&lookAndFeel);

     addAndMakeVisible(&first);
    firsr.setText("Please insert a numeric value");
    first.getText() >> text;
}

//…
private:
TextEditor first;
int text;

//—
What I’m trying to do is to transfer the input a the value from the text editor to an integer. With the first.getText() >> text . I have a hunch this is not how you do it and if that’s the case then how do you convert a string to an integer? Cause if i transfer the value from getText to a string it works just fine.

Thanks.


#4

Check out the JUCE String class – it has methods to convert from String to int, long, etc.

Rail


#5

const int x = first->getText()->getIntValue();