|
5Qter豆
QJSON文件中有中文字符串,QT5.5.1进行解析时,中文会乱码显示,解析方式如下:
map0[i]=result[SAFC_str[i]].toMap();//第0层 map0_name[i]=map0[i]["name"].toString();
网上搜了下,以下几种方法都不能解决
1)在main()函数内的添加代码,利用QTextCodec来进行设置。
// 以下部分解决中文乱码 QTextCodec *codec = QTextCodec::codecForName("utf8"); //GBK gbk QTextCodec::setCodecForTr(codec); QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForCStrings(codec); // 以上部分解决中文乱码---------NO
2)具体的转换代码看下面:
#include <QApplication>
#include <QTextCodec>
#include <QLabel>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
QLabel hello(QObject::tr("你好世界"));
hello.setWindowTitle(QObject::tr("Qt中文显示"));
hello.show();
return app.exec();
}
------qt4方法,NO
|
|