标题:请教关于tr()
作者:btwo0
日期:2007-01-31 11:20
内容:
两个问题:
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()会限定字符串的长度,哪位帮帮忙?
谢谢!
#1 [btwo0 02-05 17:48]
我尝试了用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无法显示中文,依然是英文显示
谢谢
#2 [btwo0 02-07 14:45]
Hi, the problem has fixed, if I ues QT_TR_NOOP macro
thanks all