• 7637阅读
  • 2回复

请教关于tr() [复制链接]

上一主题 下一主题
离线btwo0
 

只看楼主 倒序阅读 楼主  发表于: 2007-01-31
请教关于tr()
两个问题:
1. tr()函数好像只能翻译一定长度的字符串,示例代码:
QString str1 = QObject::tr("gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
QString str2 = QObject::tr("gg");
QPushButton button1 = QPushButton(this);
QPushButton button2 = QPushButton(this);
button1->setText( str1 );
button2->setText( str2 );
奇怪的是,button2可以显示中文,button1无法显示中文,依然是英文显示。当我将str1的长度减少后,button1就可以显示中文了,但我并没有看到有文档说明tr()会限定字符串的长度,哪位帮帮忙?
谢谢!

[ 此贴被XChinux在2007-02-07 14:52重新编辑 ]
离线btwo0

只看该作者 1楼 发表于: 2007-02-05
我尝试了用QString.arg()去拆分长字符串,示例代码:
QString str1(%1 %2).arg(QObject::tr("gggggggggggggg")).arg(QObject::tr("gggggggggggggggggggggg"));
QPushButton button1 = QPushButton(this);
button1->setText( str1 );
OK,现在button1上可以显示中文了, 有新的问题,当我将str1作为参数传入其他函数如
test(str1), 其函数实现为
void test(QString &str)
{
QPushButton button2 = new(this);
button2->setText(str);
}
button2无法显示中文,依然是英文显示
谢谢
离线btwo0

只看该作者 2楼 发表于: 2007-02-07
Hi, the problem has fixed, if I ues QT_TR_NOOP macro
thanks all
快速回复
限100 字节
 
上一个 下一个