Save the text of a text area object in its delete event


I want to save the text of a text area object in my application, so I decided to do this in its LV_EVENT_DELETE event. but I got hard fault. I think it’s because of that the childeran of ta is deleted by then and so we can not get its text. what do you think? Is there any better solution?

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

STM32F429, CubeIDE, GCC

What do you want to achieve?

get the text of a text area in its delete event.

What have you tried so far?

This is the callback of ta_first_name which caused to a hard fault.

static void ta_first_name_callback(lv_obj_t *obj, lv_event_t event)
	(void) obj; /*unused*/

	if(event == LV_EVENT_DELETE) {
		char *str_first_name = lv_ta_get_text(obj);

I can’t think of a clean solution right now, because there is currently no event that gets fired on the parent object before the children are deleted. The only thing I can think of would be for you to set an event handler on the child object (lv_ta_get_label(ta)).

static void ta_child_callback(lv_obj_t * ta_label, lv_event_t event)
    if(event != LV_EVENT_DELETE)
    lv_obj_t * ta = lv_obj_get_parent(lv_obj_get_parent(ta_label));
    const char * txt = lv_ta_get_text(ta);
    /* Do something with 'txt' */
lv_obj_set_event_cb(lv_ta_get_label(ta), ta_child_callback);

In dev-7.0 we could possibly add LV_EVENT_WILL_DELETE which would fire before any deletion happens.


I can also suggest this solution!

thanks to both of you.
with a little bit of modification, it worked for me.