PDA

View Full Version : ° character



Windsoarer
16th June 2009, 08:17
Hi all

In a display widget such as a QLabel, I'd like to introduce the character ° (for degree)
For instance :


QLabel *AngleLabel = new QLabel("Angle (°)")

Although the ° character will ouput correctly on Windows, it gives strange things instead on Linux.

Is there some special coding that should be set somewhere to get it output correctly ?

Thanks

Beppe
16th June 2009, 08:29
try this


QLabel *AngleLabel = new QLabel(QString::fromUtf8("Angle (°)"))

wysota
16th June 2009, 08:38
QString by default assumes a conversion from C Strings using a local 8 bit encoding which is different for different systems. Therefore what works on Windows will not work on Linux. You need to explicitely set what encoding should be used either by QTextCodec::setCodecForCStrings() or by explicitely saying which codec to use for a particular conversion, for instance QString::fromUtf8().

nish
16th June 2009, 08:38
same problem came to me.... but on windows too.

the solution is


QChar ch(0xNN); //replace NN with the unicode charecter code for the degree symbol
QString s="Angle (";
s.append(ch);
s.append(")");
QLabel *AngleLabel = new QLabel(s);

Windsoarer
16th June 2009, 08:51
Great, it worked.

Thanks for your kind and quick answers