Solved QTranslator do not work at all
-
os : windows 10 64 bits
Qt : 5.9.4, vc2017 64bits- Wrap the text by tr or QObject::tr.
- Generate the ts file,
- Translate almost every words of the ts file(some of them are left empty).
- Run lrelease to generate qm file
- Load the qm file as following
QTranslator custom_translator_; qDebug()<<__func__<<a.applicationDirPath(); if(custom_translator_.load("english_to_turkish.qm", a.applicationDirPath())){ qDebug()<<__func__<<"can load english to turkish"; if(a.installTranslator(&custom_translator_)){ qDebug()<<__func__<<"can install translator"; }else{ qDebug()<<__func__<<"cannot install translator"; } }else{ qDebug()<<__func__<<"cannot load english to turkish"; }
The return values tell me qm file can be loaded and installed, but none of the text are translated to Turkish, every words remain as English. Any possible wrong I commit? Thanks
-
Do you install your translations before instantiating the GUI or after?
-
@sierdzio Yes.
I find out the issue, the problem is life time, I put the QTranslator in a class, and that class is enclosed by {}, that is why the text did not translated, a stupid bug.