holst
7th October 2011, 14:21
Hi all,
I have a question about change language dynamically, but not the application language just for same forms.
The scenario is a qt application that has 2 forms:
* One simulates a HMI that can change its language
* Anothe one simulates other HMI that can change its language
So if I change the language in one HMI (form) like this:
if (translator.load(QLatin1String("idiomas_") + locale, resourceDir))
qApp->installTranslator(&translator);
ui.retranslateUi(this);
Everything seems ok, but when I start using the other HMI (form) texts with the language in the othe form are showing. That's because I calling tr() while using the second form and in the first form I've done
qApp->installTranslator(&translator);
Things that I tried without success:
1) Not call qApp->installTranslator(), but nothing changes.
2) Not call qApp->installTranslator() and not use tr() function, use
translator.traslate() instead. This works only with the text in the source but not in ui. Why? Because in funtion "ui.retranslateUi(this)" use the following for the texts:
FrmERTMSClass->setWindowTitle(QApplication::translate("FrmERTMSClass", "FrmERTMS", 0, QApplication::UnicodeUTF8));
So you have to install the translator if you want to use the ui.retranslateUi() function because it call QApplication:translate().
3) Install the new language, call ui.retranslateUi and the install the language that was before. But my problems are in the tr() functions of the first form.
So, anyone can help me?
Does anyone know how to change the language dynamically but only to a part of the application not to all the app?
Thanks in advance.
I have a question about change language dynamically, but not the application language just for same forms.
The scenario is a qt application that has 2 forms:
* One simulates a HMI that can change its language
* Anothe one simulates other HMI that can change its language
So if I change the language in one HMI (form) like this:
if (translator.load(QLatin1String("idiomas_") + locale, resourceDir))
qApp->installTranslator(&translator);
ui.retranslateUi(this);
Everything seems ok, but when I start using the other HMI (form) texts with the language in the othe form are showing. That's because I calling tr() while using the second form and in the first form I've done
qApp->installTranslator(&translator);
Things that I tried without success:
1) Not call qApp->installTranslator(), but nothing changes.
2) Not call qApp->installTranslator() and not use tr() function, use
translator.traslate() instead. This works only with the text in the source but not in ui. Why? Because in funtion "ui.retranslateUi(this)" use the following for the texts:
FrmERTMSClass->setWindowTitle(QApplication::translate("FrmERTMSClass", "FrmERTMS", 0, QApplication::UnicodeUTF8));
So you have to install the translator if you want to use the ui.retranslateUi() function because it call QApplication:translate().
3) Install the new language, call ui.retranslateUi and the install the language that was before. But my problems are in the tr() functions of the first form.
So, anyone can help me?
Does anyone know how to change the language dynamically but only to a part of the application not to all the app?
Thanks in advance.