• 5155阅读
  • 3回复

[提问]qt中文在编辑框中显示的问题 [复制链接]

上一主题 下一主题
离线tiancaixd1
 

只看楼主 倒序阅读 楼主  发表于: 2008-10-06
qt中文在编辑框中显示的问题
— 本帖被 XChinux 从 Qt基础编程 移动到本区(2013-04-01) —
我编写的软件其他地方都可以汉化,就是编辑框中显示的内容不能汉化,不知道为什么
这段程序是一个包含选择语句的函数
比如case 0: a="good";
case 1: a="bad";
return a;
然后调用上面的语句,根据条件的不同将a的内容在一个编辑框中以中文显示出来,为了翻译,我将a="good";改为a=QT_TR_NOOP("good");以此类推,这样写有问题吗,tr应该在这里不能用吧。
离线lazybone
只看该作者 1楼 发表于: 2008-10-06
未遇到此问题
离线benkei

只看该作者 2楼 发表于: 2008-10-06
QTextCodec类,用tounicode转化试过没有,utf8或GBK编码都可以。

codec->toUnicode("中文")
离线jinyu
只看该作者 3楼 发表于: 2008-10-08
参考下这个吧,不知道对你是否有用
1 使用QString的fromLocal8Bit()函数
这个方法是最快的,系统直接自动将char *的参数转换成为系统默认的编码,然后返回一个QString。
#include <QApplication>
#include <QTextCodec>
#include <QLabel>

int main(int argc,char *argv[])
{
  QApplication app(argc,argv);
// QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
// QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
// QLabel hello(QObject::tr("你好"));
// QLabel hello("你好");
// hello.setWindowTitle(QObject::tr("终于搞定中文"));
  QString str;
    str = str.fromLocal8Bit("哈哈哈");
    hello.setWindowTitle(str);
    hello.show();
    return app.exec();
}
2 用QTextCodec的toUnicode方法来显示中文
#include <QApplication>
#include <QTextCodec>
#include <QLabel>

int main(int argc,char *argv[])
{
  QApplication app(argc,argv);
    QLabel hello(QObject::tr("你好").toLocal8Bit());
    QTextCodec *codec = QTextCodec::codecForLocale();
    QString a = codec->toUnicode("安师大手动");
    hello.setWindowTitle(a);
hello.show();
return app.exec();
}
快速回复
限100 字节
 
上一个 下一个