• 6066阅读
  • 4回复

【提问】编译一个简单的中文程序 [复制链接]

上一主题 下一主题
离线already
 
只看楼主 倒序阅读 楼主  发表于: 2005-12-12
源码如下:
#include <qapplication.h>
#include <qpushbutton.h>
#include <qtranslator.h>
#include <qobject.h>
#include <qtextcodec.h>
                                                                 
int main(int argc,char ** argv)
{
                                                                 
  QApplication a(argc,argv);
                                                                 
  QCString localStr = "hello 你好!";
  QTextCodec * tempCodec=QTextCodec::codecForName("gbk");
  QString unicodeString = tempCodec->toUnicode( localStr );
                                                                 
  QPushButton hello( unicodeString, 0 );
                                                                 
  hello.resize(300,200);
  a.setMainWidget(&hello);
  hello.show();
  return a.exec();
}
但是,运行显示为hello,方框 ,请问有人知道是怎么回事吗?自己编的中文应用程序总是有问题。
gcc 3.2.2 qtopia-1.7.0,qt-2.3.7
编译 qt时选的是full
离线angusliu

只看该作者 1楼 发表于: 2005-12-13
你用的是QTE,还是QT?

你的这段程序如果是在qt下执行,应该能正常中文,
但如果是在QTE下执行,需要设置一个unicode字体,

QApplication a(argc,argv);
加如下代码,
QFont font("unifont", 16);
a.setFont(font);
离线hawayi
只看该作者 2楼 发表于: 2006-10-11
我试过以上的程序了,qt下可以正常显示中文,
在qte下,编译可以通过,但要在qvfb上显示时会出现段错误。
不知道这是什么问题呢,能否帮忙解答一下,困惑好久了
离线onebyte

只看该作者 3楼 发表于: 2006-10-12
最好用调试工具在调试过程中发现到底段错误发生在什么位置
离线shiroki

只看该作者 4楼 发表于: 2006-10-20
八成是tempcodec指针是空指针。 你的TEXTCODEC没有编译进qte的库吧 ? 检查qconfig-xxx.h文件里的宏
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
快速回复
限100 字节
 
上一个 下一个