Send custom data to callback function


Hello, i started to learn lvgl. So i tried to write a simple programm. I have button and led.
I want on the led when the button is pressed.I achieved this.But I think there is a better way to do it.

What MCU/Processor/Board and compiler are you using?

Simulator, gcc

What LVGL version are you using?

lvgl 7.3.1

What do you want to achieve?

I want to send custom data to callback function when button pressed, like in lv_event_send(obj, LV_EVENT_…, &custom_data).
I have read the documentation but cannot find something similar to what I want. If I missed something, please tell me which section I should read

Code to reproduce

My code

#include "../../lv_examples.h"
static lv_obj_t * led;

static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
    if(event == LV_EVENT_CLICKED) {
void myfunc(void)
    lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); 
    lv_obj_set_pos(btn, 10, 10); 
    lv_obj_set_size(btn, 120, 50);

    lednext = lv_led_create(lv_scr_act(),NULL);

    lv_obj_t * label = lv_label_create(btn, NULL);
    lv_label_set_text(label, "Next"); 


Use lv_obj_set_user_data to store a reference to the LED object. You can then retrieve it in the event callback with lv_obj_get_user_data.

I add ‘‘lv_obj_set_user_data(btn,&led);’’ in myfunc and ‘‘int * led = lv_obj_get_user_data(btn); lv_led_on(led);’’ in btn_event_cb. But I have error "undefined reference to lv_obj_get_user_data() and lv_obj_set_user_data.

Did you check that user data is enabled in lv_conf.h?

I did it. Now everything work, thanks for help