this is worked for me.(translate from English to Portuguese)
1) add this to main.cpp
QApplication app(argc, argv);
//Language Translation
//change the prefered language
QString locale = "pt" // say i am doing Portuguese language translation
QString file= app.applicationDirPath() +"/translation_"+locale;
QTranslator translator;
bool result=translator.load(file);
if ((locale != "en") && !result )
{
QMessageBox msgBox;
msgBox.setText("Unable to load language translation files");
msgBox.exec();
}
app.installTranslator(&translator);
2) Say if you are going to translate the MainWindow.ui
click the Translatable tick box in each and every lable in that MainWindow.ui using QT Designer. (you have nothing to do in the gui other than this)
3) create translation_pt.ts file as mentioned below. Make sure to put classname inside the name tags
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS>
<context>
<name>MainWindow</name>
<!-- Dialog Heading -->
<message>
<source>Glasses Fitment Details</source>
<translation>Detalhes de Calibração dos Óculos</translation>
</message>
<!-- Fitter -->
<message>
<source>Fitter</source>
<translation>Ajustador</translation>
</message>
<message>
<source>Fitter's Name</source>
<translation>Nome do Ajustador</translation>
</message>
</context>
</TS>
4) add below line to your .pro file
TRANSLATIONS = translation_pt.ts
5) go to qt installation location and run following command
lrelease "location of the .pro file you edited in step 4"
then you will get translation_pt.qm file at that location
6) copy translation_pt.qm file to the location which your binary is running
then automatically your language in your MainWindow.ui would be translated from English to Portuguese
Thanks,
Saman