QTranslator
-
Hi guys, a doubt: I'm reading about the qtranslator class and seems to me that i can't switch the language in the execution time, only when the app is not loaded, this is correct?
On this case when the user switch the language i will need killl and restart my app, correct?
thanks! -
-
@SGaist I'm confused.
Inside my app the user select the language that hes prefer to use. On the trigger event i need translate my Ui's. But inside my class i dont see how to do it. Because the first translate on my app occurs on main.cpp, and the event that im talking stays inside on my brprint.cpp file. How to do it?
I'm trying this, but nothing happens.void BrPrint3D::on_actionPortuguese_triggered() { QTranslator trans; trans.load(":/Translations/PT_portuguese.qm"); ui->retranslateUi(this); }
-
Have you looked at the example I gave a link to?
To change the language dynamically you to do 2 things:
- install translator .
From the code i referred to:
void switchTranslator(QTranslator& translator, const QString& filename)
{
// remove the old translator
qApp->removeTranslator(&translator);// load the new translator
if(translator.load(filename))
qApp->installTranslator(&translator);
}- Update controls for every widget which needs a translation.
In the referred code this is done by calling ui.retranslateUi()
void MainWindow::changeEvent(QEvent* event)
{
if(0 != event) {
switch(event->type()) {
// this event is send if a translator is loaded
case QEvent::LanguageChange:
ui.retranslateUi(this);
break;3
- install translator .
-
This post is deleted!
-
@alex_malyu How i can access my qApp on main.cpp starting from my class A? thats my doubt. Because the action to change language is tiggered from my class A. I'm try pass qApp by reference to my class A but the qt dont accept.
-
#include <QCoreApplication>
.......
qApp->
Like a global pointer: QApplication* qApp