Skip to main content
prathima
Associate III
February 6, 2020
Question

printing updated strings in a model

  • February 6, 2020
  • 7 replies
  • 3970 views

hello people..

actually i want to display a string..

i did in this way

char buff[10]="hello";

Unicode::snprintf(buffer,10,"%s",buff);

but am not getting anything.....

in the prinf the buffer is i had the textarea from touchgfx that buffer am taking here...

can you sortout my issue

thank you...

7 replies

jimmii
Senior II
February 6, 2020
prathima
prathimaAuthor
Associate III
February 6, 2020

Thank you jimmi.....

but i have seen this article ...but my way of doing it is ...i had a text with blank and wildcard of size 10 in touchgfx.

In the model i have defined int i2c=100;

and am printing it in view....using Unicode::snprinf(TexareaBuffer,10,"%d",i2c);

this is working fine, but in the place of int variable i2c=100, i want to declare a buffer like this.............................. char buff[10]="hello";

this i want to display in view..

i did like this

Unicode::snprinf(TexareaBuffer,10"%s",buff);

but it is displaying question mark(?)

if i do directly Unicode::snprinf(TexareaBuffer,10"%s","hello");

the same issue...

so that is why i asked about how to print a string only string not integer..

and in touchgfx i written Wildcard char is 0-F and wildcard range 0-9..still same issue..

please help me to fix this issue....

JHarding
Senior
February 6, 2020

I just ran into this issue the other day.

If you want to take a character array like you have and stuff it into a TouchGFX text buffer you need to do a couple things.

  • Use Unicode::strncpy to convert your char array to Unicode.
  • Make sure the font associated with the TextArea has wildcards for the characters in your char array
  • Make sure that the text field is being resized to fit all of the text you are adding by calling resizeToCurrentText() on the TextArea object.
  • Lastly, make sure you are calling the invalidate() function on the TextArea object.

Also, this page is your best friend. It contains a wealth of information on this topic: https://touchgfx.zendesk.com/hc/en-us/articles/207015345-Using-texts-and-fonts?mobile_site=true

prathima
prathimaAuthor
Associate III
February 6, 2020

it is working now,,,,,, but when i want to leave initially my wildcard is empty in that case it is not working...

i want it works in this case also...

i have filled my wild card with abcdefghij.

if i want to print "zxzx" which i haven't written in wild card then it's giving quesion marks again...i have to make it works in this case also... why because we can not write all the chacters in wild card .....please help me...

prathima
prathimaAuthor
Associate III
February 6, 2020

it is working now,,,,,, but when i want to leave initially my wildcard is empty in that case it is not working...

i want it works in this case also...

i have filled my wild card with abcdefghij.

if i want to print "zxzx" which i haven't written in wild card then it's giving quesion marks again...i have to make it works in this case also... why because we can not write all the chacters in wild card .....please help me...

Like

Reply

Select as Best

prathima
prathimaAuthor
Associate III
February 6, 2020

i was trying by writting A-F in wildcard character under typoghrapies under texts in touchgfx but if i write "AvgdbdvZ" in my buffer...

it is displaying "A??????F" it is treating it as A and - and F but it should take all characters ...what is the issue in this case

 char buff[20] = "AvgdbdvZ";

 Unicode::strncpy(textArea1Buffer, buff,20);

     textArea1.invalidate();

     textArea1.setWildcard(textArea1Buffer);

      textArea1.resizeToCurrentText();

       textArea1.invalidate();

i have written code like this....

JHarding
Senior
February 6, 2020

This is the code that I have that works:

char string[20]="AvgdbdvZ";
touchgfx::Unicode::UnicodeChar dst[20];
Unicode::strncpy(dst, string, 20);
Unicode::snprintf(testOutputTextAreaBuffer, TESTOUTPUTTEXTAREA_SIZE, "%s", testOutputTextAreaBuffer, dst);
testOutputTextArea.invalidate();
 

ETale.1
Associate II
November 16, 2020

thanks!!!, your reply was very helpful !

I got stuck at this part of program but after reading the code you posted I could fix the issue.

prathima
prathimaAuthor
Associate III
February 6, 2020

sry:) dear JHard it is working fine now...issue fixed

thank you very much....

JHarding
Senior
February 6, 2020

No problem, glad you got it working!

prathima
prathimaAuthor
Associate III
February 7, 2020

helo..how to pass a string from model to view

thank you

prathima
prathimaAuthor
Associate III
February 7, 2020

hello....

actually am trying to pass a string which is defined in model.cpp

up to presenter i can able to pass the whole string but when am passing to the view only i can able to get only first character...why this issue

void Model::tick()

{

tickCounter++;

char buff[20] = "hello hai";

if (modelListener != NULL)

modelListener->notifythetext(buff);

}

modellistener.hpp:

 virtual void notifythetext(char*) {}

presenter.cpp:

void Screen1Presenter::notifythetext(char *buff) {

view.newnotify(*buff);

}

presenter.hpp

 virtual void notifythetext(char*);

view.cpp:

void Screen1View::newnotify(char buff)

  touchgfx::Unicode::UnicodeChar dst[20];

  Unicode::snprintf(textArea1Buffer, 20, "%s", textArea1Buffer, dst);

  textArea1.invalidate();

  textArea1.setWildcard(textArea1Buffer);

  textArea1.resizeToCurrentText();

  textArea1.invalidate();

}

view.hpp:

 virtual void newnotify(char);

can you fix my issue

thank you

JHarding
Senior
February 7, 2020

Inside of the function void Screen1View::newnotify(char buff) you never copy buff into dst using the Unicode::strncpy() function.

prathima
prathimaAuthor
Associate III
February 7, 2020

 hello ..

I am trying to pass a string from model to view and am printing that into view ....whenever i change the string in model it sholud effect to view also....am can't able to do it while am passing, presenter taking whole string,but view receiving only 1st character..please fix my issue

thank you