Lv_event_get_user_data() gives invalid conversion error

Important: unclear posts may not receive useful answers.

Description

When trying to load examples into platform IO from LVGL, I’m getting conversion errors when I try to compile, specifically with function lv_event_get_user_data() invalid conversion from ‘void*’ to ‘lv_obj_t*’ {aka ‘_lv_obj_t*’} [-fpermissive].

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

WT32-SC01 (ESP32) / PlatformIO through VS Code

What LVGL version are you using?

8.3.2

What do you want to achieve?

Utilize lv_event_get_user_data correctly, prevent invalid conversion from ‘void*’ to ‘lv_obj_t*’ {aka ‘_lv_obj_t*’} [-fpermissive] errors

What have you tried so far?

Compiling other examples that this error isn’t flagged / doesn’t use the get_user_data() function. It compiles and works as expected on my hardware.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

static void anim_x_cb(void * var, int32_t v)
{
    lv_obj_set_x(var, v);
}

static void sw_event_cb(lv_event_t * e)
{
    lv_obj_t * sw = lv_event_get_target(e);
    lv_obj_t * label = lv_event_get_user_data(e);

    if(lv_obj_has_state(sw, LV_STATE_CHECKED)) {
        lv_anim_t a;
        lv_anim_init(&a);
        lv_anim_set_var(&a, label);
        lv_anim_set_values(&a, lv_obj_get_x(label), 100);
        lv_anim_set_time(&a, 500);
        lv_anim_set_exec_cb(&a, anim_x_cb);
        lv_anim_set_path_cb(&a, lv_anim_path_overshoot);
        lv_anim_start(&a);
    } else {
        lv_anim_t a;
        lv_anim_init(&a);
        lv_anim_set_var(&a, label);
        lv_anim_set_values(&a, lv_obj_get_x(label), -lv_obj_get_width(label));
        lv_anim_set_time(&a, 500);
        lv_anim_set_exec_cb(&a, anim_x_cb);
        lv_anim_set_path_cb(&a, lv_anim_path_ease_in);
        lv_anim_start(&a);
    }

}

/**
 * Start animation on an event
 */
void lv_example_anim_1(void)
{
    lv_obj_t * label = lv_label_create(lv_scr_act());
    lv_label_set_text(label, "Hello animations!");
    lv_obj_set_pos(label, 100, 10);


    lv_obj_t * sw = lv_switch_create(lv_scr_act());
    lv_obj_center(sw);
    lv_obj_add_state(sw, LV_STATE_CHECKED);
    lv_obj_add_event_cb(sw, sw_event_cb, LV_EVENT_VALUE_CHANGED, label);
}

Screenshot and/or video

you must change to
lv_obj_t * label = (lv_obj_t *)lv_event_get_user_data(e);
or remove -fpermissive

@spider_vc thank you so much – worked like a charm to change to lv_obj_t * label = (lv_obj_t *)lv_event_get_user_data(e); . Thanks for helping this n00b.