|
1Qter豆
这个是书上的例子。
#include <QApplication>
#include <QDialog>
#include <QLabel>
#include <QTextCodec>
int main(int argc, char **argv)
{
QApplication a(argc,argv);
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QDialog w;
w.resize(400,300);
QLabel label(&w);
label.move(120,120);
label.setText(QObject::tr("helloQt,你好Qt"));
w.show();
return a.exec();
}
书上的例子,说是能显示中文
但实际上中文的地方还是乱码。
|
最佳答案
查看完整内容
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());设置之后
label.setText(QObject::tr("helloQt,你好Qt"));
修改为
label.setText("helloQt,你好Qt");
后面加上QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
这个这么清楚
还看不懂?
我每次写程序,在main函数里面都是这样写的
QTextCodec *codec = QTextCodec::codecForLocale();
QTextCodec::setCodecForTr(codec);
QTextCodec::setC ...
|