[Qt-interest] µ char in a QLabel
Thiago Macieira
thiago at kde.org
Wed Dec 16 19:02:29 CET 2009
Em Quarta-feira 16. Dezembro 2009, às 14.03.16, Maicon Kist escreveu:
> Hi,
>
> how can i add the µ (micro sign, 0x00b5 in unicode chartset ) in a QLabel ?
>
> I have tried this:
>
> Qlabel *l = new QLabel("µ");
>
> But, In the application the label show some weird characters.
The problem is the encoding of your source file and the default encoding of Qt
mismatching.
The default encoding for QString construction directly from C strings is Latin
1. If you saw "weird characters", my guess is your source file is encoded in
UTF-8.
Your options therefore are:
1) change the encoding of your file
2) change Qt's encoding for C strings (see QTextCodec::setCodecForCStrings)
3) use QString::fromUtf8("µ")
4) use QChar(0x00B5)
Depending on which text editors you and your team use, it might be a good idea
not to leave non-ASCII characters in your source code. Opening the file in the
wrong encoding might cause it to become corrupt when saving.
So you can also write:
5) QString::fromUtf8("\302\265")
6) QString::fromLatin1("\xB5") or QLatin1String("\xB5") or even
QLatin1Char('\xB5')
I still think it's a good idea to add to C++0x requirement that C++ source
files should be decoded as UTF-8 when the new unicode character sequences are
encountered. Otherwise, writing u"µ" will result in the same issue all over
again.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091216/53272149/attachment.bin
More information about the Qt-interest-old
mailing list