April 18, 2012

ken536 ken536
Lab Rat
19 posts

°C displayed as °C

 

When I use setText for a label like this:

  1. ui->label_5->setText("°C");

It is displayed as:
  1. °C

If I set °C in Qt Designer in the form editor, everything is displayed as it should.

Why is this happening?

10 replies

April 18, 2012

AcerExtensa AcerExtensa
Robot Herder
570 posts

try this:

  1. ui->label_5->setText(tr("°C"));

 Signature 

God is Real unless explicitly declared as Integer.

April 18, 2012

ken536 ken536
Lab Rat
19 posts

Nope doesn’t work.
tr is for translating, why do you think it works for this?

April 18, 2012

AcerExtensa AcerExtensa
Robot Herder
570 posts

See here [qt-project.org]

 Signature 

God is Real unless explicitly declared as Integer.

April 18, 2012

GentooXativa GentooXativa
Lab Rat
126 posts

Maybe you are saving your files with a wrong enconding? Check it at Options -> Text Editor

 Signature 

Jose Vicente Giner Sanchez - Senior Mobile Developer

www.gigigo.com

C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
T: +34 917431436

April 18, 2012

ken536 ken536
Lab Rat
19 posts

Changing Encoding doesn’t make any changes. TRUTF8 does the job :)

April 18, 2012

AcerExtensa AcerExtensa
Robot Herder
570 posts

Please add [SOLVED] to topic subject.

 Signature 

God is Real unless explicitly declared as Integer.

April 18, 2012

ken536 ken536
Lab Rat
19 posts

  1. void MLineEdit::setLblText2(QString s )
  2. {
  3.     label2->setText(s);
  4. }

Adding trUtf8 here to s doesn’t work..

April 18, 2012

Andre Andre
Area 51 Engineer
6031 posts

Of course not, it only works with static text. You’ll have to do the translation wherever s originates.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

April 18, 2012

ken536 ken536
Lab Rat
19 posts

It is an Custom Widget:
Q_PROPERTY( QString Unit READ readLblText2 WRITE setLblText2 DESIGNABLE true SCRIPTABLE true STORED true )

April 18, 2012

AcerExtensa AcerExtensa
Robot Herder
570 posts

should look like this:

  1. this->setLblText2(trUtf8("°C"));
  2.  
  3. void MLineEdit::setLblText2(QString s )
  4. {
  5.     label2->setText(s);
  6. }

 Signature 

God is Real unless explicitly declared as Integer.

 
  ‹‹ Focus application for mac      [SOLVED] QT3D compared to GLC_lib ››

You must log in to post a reply. Not a member yet? Register here!