In that case you can move the definition of QTranslator object into your main window class (or everywhere else, just somewhere that'll keep it) and load it like before:
at mainwindow.h file:
private:
private:
QTranslator translator;
To copy to clipboard, switch view to plain text mode
In MainWindow's constructor before setupUi():
translator.load("path/to/qm/file/cs_CZ.qm");
qApp->installTranslator(&translator);
translator.load("path/to/qm/file/cs_CZ.qm");
qApp->installTranslator(&translator);
To copy to clipboard, switch view to plain text mode
When you want to change language at runtime you just load the new language and retranslate the ui:
translator.load("path/to/qm/file/en_US.qm");
ui->retranslateUi(this);
translator.load("path/to/qm/file/en_US.qm");
ui->retranslateUi(this);
To copy to clipboard, switch view to plain text mode
This way, you install the translator once and just change it's loaded language whenever needed.
Bookmarks