Translations of QMessageBox not work in Qt5.3

后端 未结 3 601
余生分开走
余生分开走 2020-12-21 08:23

I\'m a fan of Qt and update it frequently, Qt5.1->5.2->5.3.

However, the tranalations of Standard buttons like \"Ok\" \"Cancel\" \"Save\" do not work anymore in Qt5.

3条回答
  •  醉梦人生
    2020-12-21 08:55

    Starting from Qt5.3 the qt_*.qm is divided into multiple files (qt*_*.qm) and now you have to copy qtbase_*.qm to translation directory and use together.

    QString translationsPath(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    QLocale locale = QLocale::system();
    
    QTranslator qtTranslator;
    if (qtTranslator.load(locale, "qt", "_", translationsPath))
        a.installTranslator(&qtTranslator);
    
    QTranslator qtBaseTranslator;
    if (qtBaseTranslator.load(locale, "qtbase", "_", translationsPath))
        a.installTranslator(&qtBaseTranslator);
    

提交回复
热议问题