O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading translations

QTranslator (http://doc.qt.io/qt-5.9/qtranslator.html) provides the ability to load and apply binary translation files. To do that, you need to create an instance of QTranslator, have the app instance install the translator, and load a translation file. Here is how it can be implemented in main.cpp:

#include <QApplication>#include <QQmlApplicationEngine>#include <QQmlContext>#include <QTranslator>...int main(int argc, char *argv[]){    ...    QApplication app(argc, argv);    QTranslator translator;    app.installTranslator(&translator);    translator.load(QString(":/cmmonitor_%1.qm").arg(QLocale().name()));    ...}

The last line simply loads the file corresponding to the name (the language_country sequence) of the current locale. You could ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required