Problem using lv_obj_add_event_cb with extraargument

I need pass a string when a button is clicked on list

extraction code of ui_events.cpp
ssid = WiFi.SSID(i).c_str();
lv_obj_add_event_cb(btn, ui_event_botonMantenimiento, LV_EVENT_CLICKED, &ssid);

extraction code of ui.c
void ui_event_botonMantenimiento(lv_event_t * e, const char * ssid)
Serial.println(“Pintamos %-32.32s”, ssid);
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_CLICKED) {
_ui_screen_change(&ui_Configuracion, LV_SCR_LOAD_ANIM_FADE_ON, 500,
0, &ui_Configuracion_screen_init);

and the error compiling on Arduino

/C:\Users\X\Desktop\Arduino\X\ui_events.cpp: In function 'void funcionBuscarWifis(lv_event_t)':
C:\Users\X\Desktop\Arduino\X\ui_events.cpp:34:38: error: invalid conversion from ‘void ()(lv_event_t, const char*)’ {aka ‘void ()(_lv_event_t, const char*)’} to ‘lv_event_cb_t’ {aka ‘void ()(_lv_event_t)’} [-fpermissive]
lv_obj_add_event_cb(btn, ui_event_botonMantenimiento, LV_EVENT_CLICKED, &ssid);
In file included from c:\users\X\desktop\arduino\libraries\lvgl\src/core/lv_obj.h:143,
from c:\users\X\desktop\arduino\libraries\lvgl\lvgl.h:35,
from c:\Users\X\Desktop\Arduino\libraries\Lvgl\src/lvgl.h:17,
from C:\Users\X\Desktop\Arduino\X\ui.h:13,
from C:\Users\X\Desktop\Arduino\X\ui_events.cpp:6:
c:\users\X\desktop\arduino\libraries\lvgl\src/core/lv_event.h:237:84: note: initializing argument 2 of ‘_lv_event_dsc_t* lv_obj_add_event_cb(_lv_obj_t*, lv_event_cb_t, lv_event_code_t, void*)’
struct _lv_event_dsc_t * lv_obj_add_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter,
Any idea? Thanks in advance

this is right cb , you cant add next params. User data is part of e then read it simmilar as you get target

To get the text in a button’s ‘pressed’ callback you can use the user_data member of the passed event struct, as Marian_M briefly says. So if you want to avoid a global variable as the text source and avoid calling the list-widget directly, you need to create a static text-pointer (OptionText) and pass its reference (pointer) to the event setter functions (which are in e.g. ui/screens/ui_Screen1.c by default in SquareLine Studio export). For example:

static char* OptionText = "Select";

lv_obj_add_event_cb(ui_Button1, ButtonPressed, LV_EVENT_CLICKED, &OptionText );
lv_obj_add_event_cb(ui_Dropdown1, OptionSelected, LV_EVENT_VALUE_CHANGED, &OptionText );

It’s important that OptionText’s pointer’s reference is passed as argument because that won’t change even if the pointer changes to point to a new text. (‘user data’ itself shouldn’t/can’t change after registering the callback because there’s no set_user_data counterpart of the get_user_data function below, and even if modifying event’s user_data member is possible, it would be a hack.)

Then the callbacks (usually in ui_events.c) could look something like this:

void ButtonPressed(lv_event_t * e)
char** StringPointer = lv_event_get_user_data( e );

printf( "%s\n", *StringPointer );

void OptionSelected(lv_event_t * e)
static char Buffer [ 32 ];
char** StringPointer = lv_event_get_user_data( e );

lv_obj_t* Selector = lv_event_get_target( e );
lv_dropdown_get_selected_str( Selector, Buffer, sizeof(Buffer) );

*StringPointer = Buffer;

printf( "Selected %s\n", *StringPointer );

Pressing the button before selecting anything would print the default text ‘Select’, but as soon an option is selected from the drop-down list, its callback would set OptionText pointer to the selected text of the dropdown (remaining in ‘Buffer’), and then the button would get that text afterwards.
This is just a dirty example but I guess it shows how passing texts around in callbacks through user_data can be approached.