View Full Version : ° character

16th June 2009, 09: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 ?


16th June 2009, 09:29
try this

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

16th June 2009, 09: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().

16th June 2009, 09: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 (";
QLabel *AngleLabel = new QLabel(s);

16th June 2009, 09:51
Great, it worked.

Thanks for your kind and quick answers