首页| 论坛| 消息

标题:中文编码问题
作者:miaoronghua
日期:2009-03-27 17:29
内容:

#include
#include
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
w.setMinimumSize(320,240);
w.setMaximumSize(320,240);
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
QPushButton hello(QPushButton::tr("文本文件world"),&w);
hello.setGeometry(20,20,160,50);
w.show();
return a.exec();
}
以上是我用QTCREATOR写的一段程序,直接编译中文可以显示 ,然后我用X86交叉编译想
先在QVFB里面看效果,结果不行阿,连乱码都没有,world直接显示在BUTTON的中央,请教中文字体显示的问题
源码我已经贴上来了,谢谢


#1 [xiner81215 03-30 14:36]
你没有设置字体.试试a.setFont(QFont("wenquanyi",16));
#2 [many_many 04-03 16:14]
#include
#include
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
w.setMinimumSize(320,240);
w.setMaximumSize(320,240);
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
QPushButton hello(QPushButton::tr("文本文件world"),&w);
hello.setGeometry(20,20,160,50);
w.show();
return a.exec();
}
把它改成红色的那样就ok了。
#3 [many_many 04-03 16:19]
#include
#include
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
w.setMinimumSize(320,240);
w.setMaximumSize(320,240);
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
QPushButton hello(QPushButton::tr("文本文件world"),&w);
hello.setGeometry(20,20,160,50);
w.show();
return a.exec();
}
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
QPushButton hello(QPushButton::tr("文本文件world"),&w);
这两句话可以这样写:
QTextCodec textContent = QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
QString textConet = code.toUnicode("文本文件world");
QPushButton hello(textConet ,&w);
#4 [yfgong 04-09 10:45]
主程序中加入:
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
运行时加上 -font wenquanyi
就可以了,我的就这样运行的。

回复 发表
主题 版块