TextEditor Listener


#1

I amtrying to put the current contents of a TextEditor box into a variable. I thought overidding might be the way to go. But perhaps adding a listner is what I should be doing.

Here’s the code so far:

TextEditor* uidBox = new TextEditor();
startWindow->addAndMakeVisible (uidBox);
uidBox->setBounds (106, 270, 202, 19);
uidBox->setText (T(“testcase”));

When I try to add a listener I get an error:
uidBox->addListener(this);
error C2664: ‘juce::TextEditor::addListener’ : cannot convert parameter 1 from 'JUCEStartApplication *const ’ to 'juce::TextEditorListener *const ’

Been trying for the last 12 hours to figure this out.

Thanks,
r.b.


#2

well if you want to use a class as a listener, you have to actually make it a subclass of TextEditorListener… how else could it receive the callbacks?!

But I don’t recommend using your JUCEApplication class for anything like this, and it definitely shouldn’t be derived from any other classes such as the listener classes - use the application object just to get things started, and put your logic into other classes, such as a main window class. The juce demo’s got plenty of examples of listeners and stuff like this.


#3

All I really want to do is add a text box to my component and update a char * with that info so I can spawn a program with the correct command line when a button is clicked:

void clicked()
{
char * _cmd = “”;


get text from uidBox
move the text into the char * _cmd

char *arg_list[] = { “program.exe”, _cmd, NULL };

}


#4

you don’t need to override TextEditor to do anything like that.

You add and position a TextEditor on a Component (which is how you get a widget to appear on a space in your window). The Component you add it to (which you’re defining yourself) should be derived from TextEditorListener; this makes it listen to changes in the TextEditor. Look at the virtual functions given to you by TextEditorListener, and use the appropriate one to define the behaviour you want (when the user has typed in something).


#5

Actually, if you just want the text when a button is clicked, then when the button is clicked just do m_MyTextBox->getText() or whatever the method was, no need for a listener on the text box.


#6

I am a dope. Finally figured out the whole thing with help from the posters here.

Thanks


#7