Skip to main content
GMeur
Associate III
Feb 15, 2019 10:26 AM UTC
Question

getTypedText() access error

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.

This topic has been closed for replies.

5 replies

Mon2
Senior III
Feb 16, 2019 4:30 AM UTC

Hi. Can you try with

getText() 	

instead of

getTypedText()

and post your update?

GMeur
GMeurAuthor
Associate III
Feb 18, 2019 7:28 AM UTC

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

Martin KJELDSEN
Principal III
Feb 18, 2019 9:09 AM UTC

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
Feb 18, 2019 1:57 PM UTC

@Martin KJELDSEN​ , thanks for the clarification.

Hey, @GMeur​ , you are welcome for the assistance :)

Natali
Associate III
Feb 2, 2020 7:48 PM UTC

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