LabelListener question

I get a trouble by using LabelListener on a Label.

I made the Label setEditable(false, true, false);

Thus when I leave focus, changement are considered.

Ok, but in this particular case, the method “labelTextHasChanged()” is not called and this is an issue to me.

How can I fix it please ?


nobody ?..

Did you make sure to call myLabel->addListener(theLabelListener)?

Yes of course :wink:

Note that the LabelListener is too the parentComp…

I’d start by placing some breakpoints. Is Label::addListener() called when you think it is? is Label::handleAsynchUpdate() called to notify the listeners when you think it should be?

Yes th eLabel::addListener() is called right in the parentComponent constructor (which inherits from LabelListener)

ParentComp::ParenrComp() { myLabel = new Label(...); myLabel->addListener(this); }

Pardon my ignorance, but Ive not token care of handleAsynchUpdate().
What is your proposal : to put “textWasEdited()” inside it ?


No, handleAsynchUpdate() is where the call to all the LabelListeners is made when things in the label change. I was thinking that if you put a breakpoint there, you could see if 1)there were any listeners for that label and 2)follow the call to see why your listener wasn’t being invoked.

Well thanks, but there is a LabelListener for my label :
when I edit it, and I press “return key”, the callback “labelTextHasChanged” rules : for instance if I specify a tempo in a box, 138 BPM, I get the tempo changed.

But if i edit the label with a value, e.g. 60 BPM, and I dont press “return” but I click outside of the label (means a loss of focus), then my BPM is always 138 !

… thus you can see the LabelListener is here, but works a half…

What is the third parameter of your call to Label->setEditable() set to? If it’s set to true, then when you click outside the label, the label will loose focus, and that signals that the editor should discard all changes.

It sounds like you want that third parameter to be “false”

Yes it does, but it is correctly set to “false” since beginning in my code…

…the matter is not finally that change are not discard"ed"…
because they are not.

When i make focus be lost, the label changes ! but the “labelTextChanged()” meth is not called :evil:

So set some breakpoints and let us know what’s happening:

I assume this is being called when you click outside your editor

if textEditorFocusLost() is called, then what happens here? Is textEditorReturnKeyPressed() called as expected?

Is updateFromTextEditorContents() called?

Is triggerAsyncUpdate() called?

At some point in this chain, things aren’t working. Place some breakpoints and let us know what is and what isn’t working.

I assume this is being called when you click outside your editor [/quote]
Well well well, I just tried it more seriously : IN FACT : when I change the text, and click outside from the editor, it s ok.

The trouble comes from if i click outside without modifying text from original state… So obviously “labelTextChanged()” not called !!!

Im stupid.

But as excuses, i was assuming that get off from editor state was considered as a LabelTextChanged…

So, I’d finally need it :
a method called when the text editor is turned off…

Thks igor

But why exactly do you need a callback if the value hasn’t changed?

cause i’m re-organizing my component according to the visibility of the text editor…

Thus whatever happens (text change or no) I have to be called back about.