我使用的翻译和语言学家在我的Qt应用symbain翻译的语言,但我想这样做对飞(上运行时),我试图通过开发者网络提供的解决方案,但它不是为我工作
#include "languagetranslator.h"
#include "constants.h"
#include <QSettings>
#include <HelperClasses/Strings.h>
#include <QTranslator>
#include <AppStatus/appstatus.h>
#include <QApplication>
QTranslator* LanguageTranslator::current = 0;
LanguageTranslator::LanguageTranslator(int& argc, char* argv[]) : QApplication(argc, argv)
{
}
LanguageTranslator::~LanguageTranslator()
{
}
void LanguageTranslator::loadTranslation()
{
QString language;
language = AppStatus::getCurrentLanguage();
loadTranslation(language);
qDebug("language from laodtranslation = %s",language.toLatin1().data());
//qDebug(language.toLatin1());
}
void LanguageTranslator::loadTranslation(QString language)
{
//QApplication app;
QTranslator* translator = new QTranslator(instance());
translator->load(language);
installTranslator(&translator);
//exec();
}
它只有当我在main.cpp中宣布它并重新启动应用程序的工作,我也呼吁在选择新语言后,这种方法是有,我错过任何东西。 我下面下面的链接http://www.qtcentre.org/wiki/index.php?title=Dynamic_translation_in_Qt4_applications
我必须调用无效的MainWindow :: changeEvent中(QEvent的*事件)设置新的语言时,
这是我在主窗口已经宣布从这里我打电话setLanguage()我changeEvent中()方法;
void MainWindow::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
// retranslate();
setLanguage();
}
QMainWindow::changeEvent(event);
}
void MainWindow::setLanguage()
{
QString myLanguage;
int iIndex = AppStatus::getSettingsData().at(3);
switch(iIndex)
{
case ENGLISH:
myLanguage = "language_en";
break;
case SPANISH:
myLanguage = "language_es";
break;
}
AppStatus::saveCurrentLanguage(myLanguage);
LanguageTranslator::loadTranslation(myLanguage);
}
从setLangauge()我打电话的languageTranslator()有什么,我很想念; 这是我的主类
int main(int argc, char *argv[])
{
LanguageTranslator app(argc, argv);
QString lang = AppStatus::getCurrentLanguage();
app.installTranslator(&translator);
MainWindow mainWindow;
mainWindow.setOrientation(MainWindow::ScreenOrientationLockPortrait);
//About mainWindow;
#if defined(Q_OS_SYMBIAN)
mainWindow.showMaximized();
#else
mainWindow.show();
#endif
// mainWindow.showFullScreen();
app.connect(&app,SIGNAL(lastWindowClosed()),&app,SLOT(quit()));
return app.exec();
}