Including localized strings in your application

In order to supply translated strings to the tr and qsTr functions in your application, your application needs to include a QTranslator object to read the .qm files and replace the strings provided to tr and qsTr with their translated counterparts. We can do this in your main entry point function, as follows:

QApplication a(argc, argv);
QTranslator translator;
bool result = translator.load("QtLinguistExample-epo.qm");
a.installTranslator(&translator);

    // Other window setup stuff goes here
    
return a.exec();

This code allocates a QTranslator object and loads the indicated translation file into the translator before installing it into the QApplication object. In this example, we're hardcoding the language ...

Get Application Development with Qt Creator - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.