标题:崩溃了,请大家帮帮忙吧,还是QT下中文显示的问题
作者:cimcenter
日期:2007-12-02 23:27
内容:
我用Qtdesigner 生成了个工程。一个PUSHBOX,点击之后一个MESSAGELABEL显示出汉字。其中用
下面的代码来进行中文显示,
#include "hello.h"
#include
#include
HelloForm::HelloForm( QWidget* parent, const char* name, WFlags fl):
HelloBaseForm(parent, name, fl)
{
}
HelloForm::~HelloForm()
{
}
void HelloForm::SayHello()
{
QCString str = "中文";
QTextCodec *codec = QTextCodec::codecForName("GBK");
QString strText = codec->toUnicode(str);
MessageLabel->setText(strText);
//QString str = str.fromLocal8Bit("中文");
//MessageLabel->setText(str);
}
程序编译通过,可是执行到QString strText = codec->toUnicode(str);一句时,REDHAT9发生 Abort错误。
在开发板上同样是这个结果,
换用注释掉的语句,程序可执行通过,可是显示出来的字符为乱码(不是方块)。
这是什么原因呢,请各位老师同仁指导,实验室一干人等翘首企盼。
如果我说得不清楚,请您提出来,我马上响应。
再次感谢您的热心。
#1 [cimcenter 12-02 23:28]
用的是qt embedded 2.3.7,
#2 [cimcenter 12-04 11:45]
请大家帮忙看看吧
#3 [youngst 12-04 17:52]
试试用tr翻译看看
QTextCodec::set codecForTr (QTextCodec::codecForName("GBK"));
QString str = tr("中文");
MessageLabel->setText(str);
#4 [fzy112001 12-08 10:05]
可能是编译时的配置问题,没有加上编码支持,请确认 qconfig-qpe.h 中以下几行被注释掉或者直接删除以下几行,然后再编译!
38 #ifndef QT_NO_CODECS
39 #define QT_NO_CODECS
40 #endif
祝你成功!~
#5 [shiroki 12-12 11:25]
是的哦