Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why QString not use QTextCodec::codecForLocale by default ?
QtWS25 Last Chance

Why QString not use QTextCodec::codecForLocale by default ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.1k Views
  • 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 Offline
    X Offline
    xth21
    wrote on last edited by
    #1

    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
    0
    • R Offline
      R Offline
      rcari
      wrote on last edited by
      #2

      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
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

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

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved