首页| 论坛| 消息

回复: QT4中如何实现在菜单中选择“语言”的功能?
#6 [gault 05-15 12:24]
好像还是不行哦,例子里的程序是定议了一个chooseLanguage的widget,定义了一个mainWindow,然后在chooseLanguage里创建一个mainWindow的对象,效果就是先是一个选择语言的widget,然后选择某种语言就会弹出一个某种语言的mainWindow出来,可是我现在想做的是在我的mainWindow里有一个菜单可以选择语言。
主要是看了文档中有这么一段,对能否实现这个功能感到疑惑!
The most common use of QTranslator is to: load a translation file, install it using QApplication::installTranslator(), and use it via QObject::tr(). Here's the main() function from the Hello tr() example:
 int main(int argc, char *argv[])
 {
   QApplication app(argc, argv);
   QTranslator translator;
   translator.load("hellotr_la");
   app.installTranslator(&translator);
   QPushButton hello(QPushButton::tr("Hello world!"));
   hello.resize(100, 30);
   hello.show();
   return app.exec();
 }
Note that the translator must be created before the application's widgets.
如果translator必须在我的MainWindow创建之前就必须定议好的话,那我怎么能够通过mainWindow的languageAction的triggered()信号来设置语言呢?
#7 [sinl 05-16 13:34]
你要的是能够动态切换语言的功能吧,这个论坛上曾经有个人做过一个例子,名字好像就叫i18n,你搜索一下

<< 1 2 >> (2/2)

回复 发表
主题 版块