Compare symbols

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation. We will not respond in detail to posts where you haven’t read the relevant documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

I have some labels in an array and I want to be able to determine which symbol is being displayed by any element by comparing.

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

STM32L4R5ZIVT / VisualGDB

What LVGL version are you using?

7.9

What do you want to achieve?

HI,
I would like a function that can be passed a symbol i.e. LV_SYMBOL_BLUETOOTH and then iterate through the array of labels with lv_label_get_text and then do something like a strcmp() to compare the two.

What have you tried so far?

char * labelText = lv_label_get_text(labelObj);

	if (strcmp(symbol, labelText) == 0 )
	{
		location = i;
	}

There is never a match between the symbol and the text from the label, even when they are the same

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:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Hi,

it works well for me:

  const char * symbol = LV_SYMBOL_BLUETOOTH;
  const char * text = LV_SYMBOL_BLUETOOTH;
  printf("%s\n", strcmp(symbol, text) == 0 ? "eq" : "neq");

Thanks for your reply. This is what I need to achieve:-

const char * symbol = LV_SYMBOL_BLUETOOTH;

char * labelText = lv_label_get_text(labelObj);

printf("%s\n", strcmp(symbol, labelText) == 0 ? “eq” : “neq”);

Thanks

It’s also working here:

  const char * symbol = LV_SYMBOL_BLUETOOTH;

  lv_obj_t * labelObj = lv_label_create(lv_scr_act(), NULL);
  lv_label_set_text(labelObj, LV_SYMBOL_BLUETOOTH);
  char * labelText = lv_label_get_text(labelObj);

  printf("%s\n", strcmp(symbol, labelText) == 0 ? "eq" : "neq");