diff --git a/src/libs/qrcode/lv_qrcode.c b/src/libs/qrcode/lv_qrcode.c
index fd8212f229..d0c5c667c1 100644
--- a/src/libs/qrcode/lv_qrcode.c
+++ b/src/libs/qrcode/lv_qrcode.c
@@ -204,6 +204,12 @@ lv_result_t lv_qrcode_update(lv_obj_t * obj, const void * data, uint32_t data_le
return LV_RESULT_OK;
}
+void lv_qrcode_set_data(lv_obj_t * obj, const char * data)
+{
+ if(data == NULL) return;
+ lv_qrcode_update(obj, data, lv_strlen(data));
+}
+
void lv_qrcode_set_quiet_zone(lv_obj_t * obj, bool enable)
{
lv_qrcode_t * qrcode = (lv_qrcode_t *)obj;
diff --git a/src/libs/qrcode/lv_qrcode.h b/src/libs/qrcode/lv_qrcode.h
index d343166a84..005682415d 100644
--- a/src/libs/qrcode/lv_qrcode.h
+++ b/src/libs/qrcode/lv_qrcode.h
@@ -72,6 +72,13 @@ void lv_qrcode_set_light_color(lv_obj_t * obj, lv_color_t color);
*/
lv_result_t lv_qrcode_update(lv_obj_t * obj, const void * data, uint32_t data_len);
+/**
+ * Helper function to set the data of a QR code object
+ * @param obj pointer to a QR code object
+ * @param data data to display as a string
+ */
+void lv_qrcode_set_data(lv_obj_t * obj, const char * data);
+
/**
* Enable or disable quiet zone.
* Quiet zone is the area around the QR code where no data is encoded.
diff --git a/src/others/xml/parsers/lv_xml_qrcode_parser.c b/src/others/xml/parsers/lv_xml_qrcode_parser.c
index 7de4ceb823..a9d72ec8b4 100644
--- a/src/others/xml/parsers/lv_xml_qrcode_parser.c
+++ b/src/others/xml/parsers/lv_xml_qrcode_parser.c
@@ -49,9 +49,6 @@ void lv_xml_qrcode_apply(lv_xml_parser_state_t * state, const char ** attrs)
void * item = lv_xml_state_get_item(state);
lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
- /* QR needs data after size/colors, so capture `data` while looping and apply at the end */
- const char * data_txt = NULL;
-
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
@@ -59,16 +56,9 @@ void lv_xml_qrcode_apply(lv_xml_parser_state_t * state, const char ** attrs)
if(lv_streq("size", name)) lv_qrcode_set_size(item, lv_xml_atoi(value));
else if(lv_streq("dark_color", name)) lv_qrcode_set_dark_color(item, lv_xml_to_color(value));
else if(lv_streq("light_color", name)) lv_qrcode_set_light_color(item, lv_xml_to_color(value));
- else if(lv_streq("data", name)) data_txt = value;
+ else if(lv_streq("data", name)) lv_qrcode_set_data(item, value);
else if(lv_streq("quiet_zone", name)) lv_qrcode_set_quiet_zone(item, lv_xml_to_bool(value));
}
-
- if(data_txt) {
- lv_result_t r = lv_qrcode_update(item, data_txt, (uint32_t)lv_strlen(data_txt));
- if(r != LV_RESULT_OK) {
- LV_LOG_WARN("lv_qrcode_update() failed");
- }
- }
}
/**********************
diff --git a/tests/src/test_cases/xml/test_xml_qrcode.c b/tests/src/test_cases/xml/test_xml_qrcode.c
index 53ffd2adc5..2fe6af83af 100644
--- a/tests/src/test_cases/xml/test_xml_qrcode.c
+++ b/tests/src/test_cases/xml/test_xml_qrcode.c
@@ -33,8 +33,8 @@ void test_xml_qrcode_with_attrs(void)
"size", "150",
"dark_color", "0x000000",
"light_color", "0xFFFFFF",
- "data", "https://lvgl.io",
"quiet_zone", "true",
+ "data", "https://lvgl.io",
"style_border_width", "1",
"style_border_color", "0x000000",
NULL, NULL,
diff --git a/xmls/lv_qrcode.xml b/xmls/lv_qrcode.xml
index ce672b8e07..169bd959e0 100644
--- a/xmls/lv_qrcode.xml
+++ b/xmls/lv_qrcode.xml
@@ -8,7 +8,7 @@ Example
-
+