cancel
Showing results for 
Search instead for 
Did you mean: 

getTypedText() access error

GMeur
Senior

0690X000006DcnzQAC.pngHello,

I'm trying to retrieve the text string of a textarea widget with the function getTypedText() but I get an access error. No wildcards are used in the textArea2, the propery "Text"is just filled in with a short text in the designer.

5 REPLIES 5
Mon2
Senior III

Hi. Can you try with

getText() 	

instead of

getTypedText()

and post your update?

Hey. getText() is not a function of the class touchgfx::TouchArea() 😉

Martin KJELDSEN
Chief III

Hi guys,

Allow me to clear up a few things. The TypedText class is a container for both Typography and Text, so you cannot use it directly in a printf statement. A TypedText does however have the getText() method.

Even then, Texts in touchgfx are 16-bit unicodes and cannot be used directly either.

typedef uint16_t UnicodeChar;

A TypedText contains a pointer to a UnicodeChar array.

Here's a small example i wrote that prints TypedText texts (Unicode::UnicodeChar*) through a small conversion method. You can also use this directly on the Unicode buffers for TextAreas with Wildcard.

Screen1.hpp:

#ifndef SCREEN1_VIEW_HPP
#define SCREEN1_VIEW_HPP
 
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
 
class Screen1View : public Screen1ViewBase
{
public:
    Screen1View();
    virtual ~Screen1View() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    void convertUnicodeToAscii(const uint16_t* in, uint8_t* out);
protected:
};

Screen1.cpp:

Screen1View::Screen1View()
{
    uint8_t output[20];
    const uint16_t* text = textArea1.getTypedText().getText();
    convertUnicodeToAscii(text, output);
    touchgfx_printf("Text: %s", output);
}
 
void Screen1View::convertUnicodeToAscii(const uint16_t* in, uint8_t* out)
{
    while(*in != 0){
        *out++ = (uint8_t)*in++;
    }
    *out = 0;
}

Output:

0690X000006DfTnQAK.png

Hope that helps.

Best regards,

Martin

Mon2
Senior III

@Martin KJELDSEN​ , thanks for the clarification.

Hey, @GMeur​ , you are welcome for the assistance 🙂

Natali
Associate II

Hi Mr Martin KJELDSEN

above code work fine. but when add wildcard text, output show unknown character.

Please guide me to use this function "const Unicode::UnicodeChar* getWildcard()const"

touchgfx_printf("Text: *%s*", output   );

0690X00000BxiRhQAJ.jpg

Best regards