Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Why QString not use QTextCodec::codecForLocale by default ?

    General and Desktop
    3
    3
    2931
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X
      xth21 last edited by

      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 ?

      1 Reply Last reply Reply Quote 0
      • R
        rcari last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • D
          dbzhang800 last edited by

          [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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post