Add Listener to ofxToggle

Hi!
I’m getting the error “ofAddListener’: no overloaded function takes 4 arguments” when I try to add a listener to a ofxToggle. Do you know where I’m wrong? Thanks.

void ofApp::update(){
	...
	rubber.addListener(this, &ofApp::rubberClicked);
	...
}

void ofApp::rubberClicked(bool toggleValue) {
	cout << "rubber" << endl;
}

It’s not a good way to add listener in update() function. It’s better to add listener in setup() function after you initialize your ofxToggle object. And you should use reference (&) when adding listener to your gui objects. Should be as follows;

void ofApp::setup(){
	...
	rubber.addListener(this, &ofApp::rubberClicked);
	...
}

void ofApp::rubberClicked(bool & toggleValue) {
	cout << "rubber: " << toggleValue << endl;
}
1 Like

It works perfectly, thanks a lot!