Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. Why the Japanese sometimes garbled in utf8 mode?
Forum Updated to NodeBB v4.3 + New Features

Why the Japanese sometimes garbled in utf8 mode?

Scheduled Pinned Locked Moved The Lounge
5 Posts 4 Posters 2.2k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    brsfjzzfxl
    wrote on last edited by
    #1

    I hava include this in main.cpp:

    QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
    
    But the Japanese sometimes garbled.
    SO I am very confused about it。
    

    This is the picture。!http://static.oschina.net/uploads/space/2013/0514/164001_Aj8d_264056.png()!

    1 Reply Last reply
    0
    • musimbateM Offline
      musimbateM Offline
      musimbate
      wrote on last edited by
      #2

      Hi I had the same problems in an application I am working on and I had trouble displaying chinese characters in a QMessageBox for example.This got the problem solved:

      @ QString str;
      str=str.fromLocal8Bit("这是一条语句");
      mMessageBox.setText(str);@

      Hope this helps

      Why join the navy if you can be a pirate?-Steve Jobs

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tzander
        wrote on last edited by
        #3

        Where does the text come from? You should make sure that the file it is in is utf8.
        I suggest using an external document you load and not text you type in your .cpp files.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          musimbate: I would recommend making sure the code files are set to UTF-8 encoding and then use fromUtf8. fromLocal8Bit might work for you, but it will fail for your users that have a different default system encoding than the one you used to save your files.

          FromLocal8Bit is meant for text you got from the system (e.g. output of commands that were run), not for text where you can actually know the original encoding.

          1 Reply Last reply
          0
          • musimbateM Offline
            musimbateM Offline
            musimbate
            wrote on last edited by
            #5

            Thanks Tobias,
            My code files are set to UTF-8 but I was getting scrambled nonsense text displayed in my messageBox until I used FromLocal8Bit.Can my set up here cause any problems?
            [quote author="Thomas Zander" date="1368597121"]
            I suggest using an external document you load and not text you type in your .cpp files.[/quote]
            What if your application uses text that is directly embedded in your code.Want to know if there is something wrong with what I have done.
            Thanks.

            Why join the navy if you can be a pirate?-Steve Jobs

            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