[Qt-interest] QString::fromLocal8Bit vs locales

Imre PÉNTEK pentek.imre at gmail.com
Fri Aug 19 17:33:41 CEST 2011


Hello!

I wanted to convert a string from native charset to QString, I wanted a code 
that would be locale independent, and I wrote this little test code (main.cpp)

and get this output:
imi at most:~$ ./testcode
éáűőúöüóíalmafa
input was:    c3a9c3a1c5b1c591c3bac3b6c3bcc3b3c3ad616c6d6166610a, 
éáűőúöüóíalmafa
fromLocal8Bit:c383c2a9c383c2a1c385c2b1c385c291c383c2bac383c2b6c383c2bcc383c2b3c383c2ad616c6d6166610a, 
éáűÅúöüóíalmafa
fromUtf8:     c3a9c3a1c5b1c591c3bac3b6c3bcc3b3c3ad616c6d6166610a, 
éáűőúöüóíalmafa
imi at most:~$ echo $LANG
hu_HU.utf8

fromLocal8Bit result isn't correct. However when I use LANG=hu_HU luit to test 
in latin2 charset, fromLocal8Bit is almost correct (I get "\xC3\xBB" (û) 
instead of "\xC5\xB1" (ű), and I get "\xC3\xB5" (õ) instead of "\xC5\x91" 
(ő)), and fromUtf8 is absolutely wrong

Is there a locale-aware (and locale-independently reilable) way to convert 
native strings to QT strings?
-- 
With regards: Imre Péntek
E-Mail: pentek.imre at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 739 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110819/b04741a6/attachment.bin 


More information about the Qt-interest-old mailing list