Lv_label_set_text() use an array to fill in the widget name

Hi all,
on arduino IDE 2.1.1 LVGL 8.3.9
I would like to use the “lv_label_set_text” command with as widget name argument a char retrieve in an array.
I can’t compile.

const char* toto[45] = {
"tata",
"titi",
...
};
 for (int i = 0; i < 45; i++){
sprintf(buff2, name[i], "%.1f °C", capteur[i]);
lv_label_set_text(toto[i], buff2);
}

use several arrays to retrieve the variables to display

Its a bit difficult to understand what you want to do.

But so far I can see that

lv_label_set_text(toto[i], buff2);

The argument toto[I] should be your LVGL label, *lv_obj_t.

Then also it may help to use

lv_label_set_text_fmt(*lv_obj_t, "%s", char text);

Thank you for the answer.
I am French and my English is very low level.
I would like to use an array with the labels LVGL (*lv_obj_t) toto[i]
i tested:

lv_label_set_text_fmt(toto[i], "%s", buff2);

and i have this error:
Compilation error: cannot convert ‘const char*’ to ‘lv_obj_t*’ {aka ‘_lv_obj_t*’}

Hi,

you cannot use char as widget name argument. You must use lv_object.

//this is your label:
lv_obj_t * label1 = lv_label_create(lv_scr_act());

//you can update like
lv_label_set_text_fmt(label1, "%.1f °C", capteur[i]);

Thanks a lot
With your explanation, I managed to do what I wanted.
here is what I did:

const char* toto[45] = {
"tata",
"titi",
...
};
 for (int i = 0; i < 45; i++){
sprintf(buff2, name[i], "%.2f ", capteur[i]);
sprintf(buff0, "%c%", toto[i]);
lv_obj_t * buff0 = lv_label_create(lv_scr_act());
lv_label_set_text(buff0, buff2);
}

Thanks again for your help.

1 Like

Good morning
I thought I had solved my problem, but no.
I will explain differently.
I have 497 variables retrieved from an XML frame and I store them in an array.
I declared all my obj* and I would like to refresh with the name of the obj* of an array from a for loop in order to reduce the sketch.

lv_obj_t * toto;
lv_obj_t *tata;
lv_obj_t *titi;

//(declaration of objects to display)

String gui[3] = {toto, tata, titi};
float capteur[3] ={1.2, -3.2, 154};

for(int i = 0 ; i <=3; i++){
sprintf(buff0, "%.1f", capteur[i];
lv_label_set_text(gui[i], buff0);
}