Why QString not use QTextCodec::codecForLocale by default ?



  • Currently,the QString cannot display correctly multi-byte characters like Chinese.(Tested on WinXP ,Chinese Version)

    To solve this problem,we must add code "QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale)" in every program .

    Why Qt not use QTextCodec::codecForLocale by default ?



  • Because your program will run OK on a Chinese Windows XP, but not on a French one. This codecForCStrings thing is runtime dependent.
    The real solution to your problem would be to save your source files in UTF-8 and use QString::fromUtf8(...) or even better, QObject::trUtf8("") for all your string literals so that you can easily translate your app afterwards and deploy it anywhere, even on other platforms.



  • [quote author="xth21" date="1343310177"]Currently,the QString cannot display correctly multi-byte characters like Chinese.(Tested on WinXP ,Chinese Version)

    To solve this problem,we must add code "QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale)" in every program .

    Why Qt not use QTextCodec::codecForLocale by default ?[/quote]

    As it's nearly always wrong to use following line
    @
    QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
    @

    in a real word and cross-platform application.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.