在板子上显示中文
宿主机的环境变量LANG="zh_CN.GBK"
include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qvbox.h>
#include <qtextcodec.h>
#include <qstring.h>
#include <qobject.h>
int main(int argc, char **argv)
{
QApplication a(argc,argv);
a.setDefaultCodec(QTextCodec::codecForName("GBK"));
QVBox box;
box.resize(200,120);
QCString chinese_string="Í˳ö";
QTextCodec* pcodec=QTextCodec::codecForName("gbk") ;
QPushButton quit(QObject::tr(chinese_string),&box);
quit.setFont( QFont( "unifont", 18, QFont::Bold ) );
QObject::connect(&quit,SIGNAL(clicked()),&a,SLOT(quit()));
a.setMainWidget(&box);
box.show();
return a.exec();
}
本文介绍了一个使用Qt进行中文字符显示的例子。通过设置环境变量及使用GBK编码,演示了如何在Qt应用程序中正确显示中文字符串,并设置了字体大小与样式。
5293

被折叠的 条评论
为什么被折叠?



