好像还是不行哦,例子里的程序是定议了一个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()信号来设置语言呢?