Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 中文乱码问题,求解决,帮忙一下

中文乱码问题,求解决,帮忙一下

Scheduled Pinned Locked Moved Chinese
5 Posts 4 Posters 6.7k 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.
  • Z Offline
    Z Offline
    zentel.
    wrote on 23 Nov 2011, 08:14 last edited by
    #1

    @
    #include <QApplication>
    #include <QLabel>
    int main(int argc, char *argv[])
    {
    QApplication app(argc,argv);
    QLabel myLabel("你好");
    myLabel.show();
    return app.exec();
    }
    @
    编译之后出现乱码,求解决方法
    我把"你好"改为tr("你好")还是不行

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zentel.
      wrote on 23 Nov 2011, 13:25 last edited by
      #2

      搞了半天终于解决了

      1 Reply Last reply
      0
      • E Offline
        E Offline
        enenglee
        wrote on 6 Dec 2011, 14:27 last edited by
        #3

        Add these words in main method as below:
        QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
        QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());

        Everyone can...

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lee0123
          wrote on 21 Feb 2012, 01:22 last edited by
          #4

          @//包含QTextCodec
          #include <QTextCodec>
          int main(int argc, char *argv[])
          {

            QApplication a(argc, argv);     
          
            //增加以下语句
          
          QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 
          
           //如果在对话框中自动获取的信息是中文(比如文件/文件夹名),增加以下语句
          
          QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
          
          //以后用tr("中文字符串")就能正确显示
          

          QLabel myLabel(tr("你好"));

           ...
          

          }
          祝大家编程愉快!

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted487
            wrote on 20 Mar 2012, 10:18 last edited by
            #5

            一般不建议使用setCodecForTr和setCodecForCStrings
            源码中一般不要使用非ascii的编码
            例如可以使用QString::fromUtf8("\u4e00")这样的代码,中文“一”

            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