求教控制台输出的Qt中文乱码怎么解决
-
-
建议你先看看 http://hi.baidu.com/cyclone/blog/item/9d7293130e5a498d6538dbf1.html
-
你调用的是
@QDebug & QDebug::operator<< ( const char * s )
@
这个函数,你最后先转成QString,然后去调用:
@QDebug & QDebug::operator<< ( const QString & s )
@
不然,它如何猜到你想用何种编码来进行转换呢?? (默认latin1)
-
-
的确应该是这样,但@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- 你调用的是
@QDebug & QDebug::operator<< ( const char * s )
@
这个函数,你最后先转成QString,然后去调用:
@QDebug & QDebug::operator<< ( const QString & s )
@
不然,它如何猜到你想用何种编码来进行转换呢?? (默认latin1)[/quote]
- 你调用的是
-
add this to the top of your cpp file
#pragma execution_character_set("UTF-8")