Getting Event Sender from Dereferenced Pointer Object

Hello, I’m struggling to get a pointer to an object via the ofAddListener callback. I used the method mentioned here; How to get the *sender from a dispatched event?

But the object is null

MyGroup * myGroup;
MyElement * myElement;

void setup() {
    myElement = &myGroup->addElement();
    ofAddListener(myElement->valueUpdated, this, &MyClass::valueUpdatedEvent);

void valueUpdatedEvent(const void * sender, int & i) {
    MyElement * el = static_cast <MyElement *> (const_cast <void *> (sender));
    ofLog() << "Received Element" << el->getName(); 

How are you notifying the event?


void setValue(int val, bool notify) {
    config["data"]["value"] = val;
    if (notify) ofNotifyEvent(valueUpdated, val);

you need to notify it sending the sender as well otherwise it’ll be null:

ofNotifyEvent(valueUpdated, val, this);

i’ve used this supposing this is the object that you consider the sender but otherwise change it with whatever you want to be received as the sender on the listener side

Yep that’s it, thank you!