.AddListener with buttons in deque

Hello, I put a collection of buttons in a deque and I trying to use the same .addlistener for each button where the .addlistener would just return the name of the button. My code for calling the listener function is,

ofParameter<ofxButton> button = board_one[index];
button.addListener(this, &ofApp::button_pressed);

and for my listener function I have,

void ofApp::button_pressed(const void * sender) {
	ofxButton * button = (ofxButton*)sender;

Looking at other posts I feel like this should work, and I have no idea what I am doing wrong, but I keep getting this error,
‘ofAddListener’: none of the 5 overloads could convert all the argument types.

Hi! I use it this way:

ofAddListener(button.myEvent, this, &ofApp::button_pressed);

instead of

button.ofAddListener(this, &ofApp::button_pressed);

You shouldn’t be creating a parameter of a button, the button itself has an event that can be listened the way @hamoid explains

Also if you want to use ofParameters instead of the gui elements directly, if you are using the nightly builds or 0.10 you can create a ofParameter<void> that when added to a panel, directly or through a parameter group, will create a button. Then you can use the parameter addListener or newListener functions to listen to that button event

hey, that should work too if there’s multiple buttons inside a group?


“hey, that should work too if there’s multiple buttons inside a group?”

so I’m trying to do exactly this I think. I have a set of toggles inside a group that sits in a gui container. Exclusive toggle= true and I want to add a listener for whenever a different toggle is selected.

However, the group gui doesn’t have a listener class I guess? What would be the correct syntax for this? All of the examples I have seen assume you have e.g. a button inside a container only, not within a group in that container.

ofParameterGroup::parameterChangedE().newListener(… ).

Here you have a snippet to make a callback to the group.
Then you can filter the added bool toggles by name.
(But this is not using lambdas. )

1 Like

Thanks, the snippet helped a lot! Got it to work :slight_smile:

cool @Maker_Bob,

Here you have another snippet, using modern lambdas, ready to copy-paste and test. (ofApp .h/.cpp)
The group 2 has the exclusive bool/toggles implemented, as you asked for.