Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. 求教控制台输出的Qt中文乱码怎么解决

求教控制台输出的Qt中文乱码怎么解决

Scheduled Pinned Locked Moved Chinese
4 Posts 3 Posters 17.6k 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.
  • S Offline
    S Offline
    shen yang
    wrote on last edited by
    #1

    求教Qt中文乱码怎么解决,
    代码
    qDebug()<<“我要显示中文”;
    输出
    [Qt Message] ?????

    程序显示的乱码可以
    QTextCodec *codec = QTextCodec::codecForName("gb18030");
    QString qstr = codec->toUnicode("大大 不是吧");
    textBrowser->setText(qstr);
    但控制台为什么总是乱码

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2
      1. 建议你先看看 http://hi.baidu.com/cyclone/blog/item/9d7293130e5a498d6538dbf1.html

      2. 你调用的是
        @QDebug & QDebug::operator<< ( const char * s )
        @
        这个函数,你最后先转成QString,然后去调用:
        @QDebug & QDebug::operator<< ( const QString & s )
        @

      不然,它如何猜到你想用何种编码来进行转换呢?? (默认latin1)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shen yang
        wrote on last edited by
        #3

        的确应该是这样,但@QDebug & QDebug::operator<< ( const QString & s )@
        我也有实验过,怀疑控制台是不是只接受latin1格式
        @ QTextCodec *codec = QTextCodec::codecForName("gb18030");
        QString qstr = codec->toUnicode("大大 不是吧");
        qDebug()<<qstr;@
        输出
        @[Qt Message] "´ó´ó ²»ÊǰÉ" @
        [quote author="1+1=2" date="1314613531"]1. 建议你先看看 http://hi.baidu.com/cyclone/blog/item/9d7293130e5a498d6538dbf1.html

        1. 你调用的是
          @QDebug & QDebug::operator<< ( const char * s )
          @
          这个函数,你最后先转成QString,然后去调用:
          @QDebug & QDebug::operator<< ( const QString & s )
          @

        不然,它如何猜到你想用何种编码来进行转换呢?? (默认latin1)[/quote]

        1 Reply Last reply
        0
        • Puppy BearP Offline
          Puppy BearP Offline
          Puppy Bear
          wrote on last edited by
          #4

          add this to the top of your cpp file
          #pragma execution_character_set("UTF-8")

          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