When I have changeEvent(QEvent* event)
with receive type event->type() == QEvent::LanguageChange
, how can I get information about what the new language is in my app?
Asked
Active
Viewed 1,346 times
1

Tay2510
- 5,748
- 7
- 39
- 58

HelloThere
- 35
- 1
- 5
2 Answers
0
You can compare the translated string with its known translations:
void changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange) {
QString translated = QCoreApplication::translate("some context", "Button");
if (translated == "Button")
// language is English
else if (translated == "Кнопка")
// language is Russian
...
}
}

svlasov
- 9,923
- 2
- 38
- 39
-
Sounds like workaround.. And won't work in case where I don't know how many languages I can have – HelloThere Apr 02 '15 at 10:49
-
This is so bad advice... – HiFile.app - best file manager Aug 12 '22 at 10:39
0
Qt don't have any object to represent application langugae. So you should implement it yorself.
Usually changeEvent(QEvent* event)
with type QEvent::LanguageChange
was caused by installTranslator(QTranslator*)
so you should know witch langugae you loaded to translator and store it locally.

Ruslan F.
- 5,498
- 3
- 23
- 42