Odd text being entered into TextEditor


#1

I added a TextEditor to my mainComponent class, which also holds a TabbedComponent. When ever I click any tabs (or buttons inside the tabs), my textEditor’s text is replaced with this…

“mation/…/src/cryptography/juce_Primes.cpp”

And I can’t seem to scroll to get anymore of the message. I also don’t see any connection (other than the password I guess) between the textEditor and juce_Primes.cpp.

Any thoughts on where to look for my coding bug?

Not sure if it’ll help, but here is my code for the mainComponent

.h

[code]#include “…/JuceLibraryCode/JuceHeader.h”
#include “MIDIMessageLogger.h”
#include “TimerThread.h”

//==============================================================================
class MainTabbedContentComponent : public Component,
public ButtonListener,
public TextEditor::Listener,
public MultiTimer
{
public:
//==============================================================================
MainTabbedContentComponent();
~MainTabbedContentComponent();

//==============================================================================

void paint (Graphics& g);
void resized();

void buttonClicked (Button* buttonThatWasClicked);
void timerCallback(int timerId);

void textEditorReturnKeyPressed (TextEditor&);
void textEditorTextChanged (TextEditor&);
void textEditorEscapeKeyPressed (TextEditor&);
void textEditorFocusLost (TextEditor&);

//==============================================================================
juce_UseDebuggingNewOperator

private:
AudioDeviceManager deviceManager;

//==============================================================================
ScopedPointer<TabbedComponent> tabbedComponent;
ScopedPointer<TextButton> write;
StringArray items;

TextEditor recordTimeInput;
TimerThread timerThread;
int recordTime;
double inc;
	
//==============================================================================
// (prevent copy constructor and operator= being generated..)
MainTabbedContentComponent (const MainTabbedContentComponent&);
const MainTabbedContentComponent& operator= (const MainTabbedContentComponent&);

};
[/code]

.cpp

[code]#include “MainTabbedContentComponent.h”
#include “AudioSetupTab.h”
#include “PerformerTab.h”

//==============================================================================
MainTabbedContentComponent::MainTabbedContentComponent()
: tabbedComponent (0),
recordTimeInput(“record_time”, 0)
{
deviceManager.initialise (0, 0, 0, true, String::empty, 0);

addAndMakeVisible (tabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
tabbedComponent->setTabBarDepth (30);
tabbedComponent->addTab (T("Audio Device Setup"), Colours::lightgrey, new AudioSetupTab (deviceManager), true);
tabbedComponent->addTab (T("Performer 1"), Colours::lightgrey, new PerformerTab (deviceManager, String::String("Performer 1")), true);
tabbedComponent->addTab (T("Performer 2"), Colours::lightgrey, new PerformerTab (deviceManager, String::String("Performer 2")), true);

addAndMakeVisible(write = new TextButton ("Record") );
write->setColour(0x1000100, Colours::lightgreen);
write->addListener (this);

addAndMakeVisible(&recordTimeInput);
recordTimeInput.setTextToShowWhenEmpty ("Rec time in MS", Colours::grey);
recordTimeInput.setInputRestrictions(6, "1234567890");
recordTimeInput.addListener(this);

recordTime = 1000;
inc = 0;
		
setSize (1000, 400);

}

MainTabbedContentComponent::~MainTabbedContentComponent()
{

}

//==============================================================================
void MainTabbedContentComponent::paint (Graphics& g)
{
g.fillAll (Colours::white);
}

void MainTabbedContentComponent::resized()
{
tabbedComponent->setBounds (0, 0, getWidth() - 0, getHeight() - 75);
write->setBounds ((getWidth()/2)-105, getHeight() - 50, 100, 25);
recordTimeInput.setBounds ((getWidth()/2)+5, getHeight() - 50, 100, 24);
}

void MainTabbedContentComponent::buttonClicked (Button* buttonThatWasClicked)
{
// Ugly code OV
// This clears the XML Files of the two perfomers to synchronize writing
PerformerTab* tempPerormer;
//performer 1
tempPerormer = dynamic_cast <PerformerTab*> (tabbedComponent->getTabContentComponent(1) );
tempPerormer->deleteAllChildElementsOfXmlElement();
tempPerormer->writeCurrentTimeStamp();
//performer 2
tempPerormer = dynamic_cast <PerformerTab*> (tabbedComponent->getTabContentComponent(2) );
tempPerormer->deleteAllChildElementsOfXmlElement();
tempPerormer->writeCurrentTimeStamp();

write->setColour(0x1000100, Colours::salmon);
startTimer(0, recordTime);
startTimer(1, 100);
timerThread.setTimerRef(inc);
timerThread.setRecordLength(recordTime);
timerThread.runThread();

}

void MainTabbedContentComponent::timerCallback(int timerId)
{
if(timerId == 0)
{
stopTimer(timerId);
stopTimer(1);
timerThread.setTimerRef((double) recordTime);
timerThread.signalThreadShouldExit();

	write->setColour(0x1000100, Colours::lightgreen);
	// Ugly code OV
	// This clears the XML Files of the two perfomers to synchronize writing
	PerformerTab* tempPerormer;
	//performer 1
	tempPerormer = dynamic_cast <PerformerTab*> (tabbedComponent->getTabContentComponent(1) );
	tempPerormer->writeXMLFile();
	//performer 2
	tempPerormer = dynamic_cast <PerformerTab*> (tabbedComponent->getTabContentComponent(2) );
	tempPerormer->writeXMLFile(); 
}
else if(timerId == 1)
{
	inc += 100;
	timerThread.setTimerRef(inc);
}

}

void MainTabbedContentComponent::textEditorReturnKeyPressed (TextEditor&)
{
recordTime = recordTimeInput.getText().getIntValue();

recordTimeInput.setCaretVisible(false);
recordTimeInput.setText(String::String(recordTimeInput.getText() + " ms"), false);

}

void MainTabbedContentComponent::textEditorTextChanged (TextEditor&)
{
recordTimeInput.setCaretVisible(true);
}

void MainTabbedContentComponent::textEditorEscapeKeyPressed (TextEditor&)
{
recordTimeInput.setCaretVisible(false);
recordTimeInput.setText(String::String(recordTime + " ms"), false);
}
void MainTabbedContentComponent::textEditorFocusLost (TextEditor&)
{
recordTimeInput.setCaretVisible(false);
recordTimeInput.setText(String::String(recordTime + " ms"), false);
}[/code]


#2

Well, you’re adding an int to a char*, and then casting it to a string (!)

What on earth is all the “String::String” weirdness about? Does that even compile!? Looks like your basic c++ skills could do with a bit of work there!


#3

Haha, Calling my C++ skills basic is paying me a compliment :slight_smile: I’m trying to go from JAVA to C++, with a very mild degree of success so far. Thanks for the tip, I’ll look into the String::String stuff. At this point I’m just hacking away until stuff compiles and works.