中文乱码问题,求解决,帮忙一下
-
wrote on 23 Nov 2011, 08:14 last edited by
@
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QLabel myLabel("你好");
myLabel.show();
return app.exec();
}
@
编译之后出现乱码,求解决方法
我把"你好"改为tr("你好")还是不行 -
wrote on 23 Nov 2011, 13:25 last edited by
搞了半天终于解决了
-
wrote on 6 Dec 2011, 14:27 last edited by
Add these words in main method as below:
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale()); -
wrote on 21 Feb 2012, 01:22 last edited by
@//包含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("你好"));
...
}
祝大家编程愉快! -
wrote on 20 Mar 2012, 10:18 last edited by
一般不建议使用setCodecForTr和setCodecForCStrings
源码中一般不要使用非ascii的编码
例如可以使用QString::fromUtf8("\u4e00")这样的代码,中文“一”