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

Marking strings for translation

The first thing that Qt's tools need to know to provide translations is what strings need to be translated. This is mostly achieved by surrounding each QString with QObject's tr function (in C++) or the qsTr function (in QML). When you need to translate strings in other contexts, a few more options are available. You can check them all out at http://doc.qt.io/qt-5.9/i18n-source-translation.html.

If, for example, we wanted to translate the Window title of cmmonitor, we should do the following:

// main.qmlimport QtQuick 2.9import QtQuick.Window 2.2Window {    visible: true    width: 640    height: 480    title: qsTr("CM Monitor")    ...}

With the qsTr approach, Qt uses the concept of a developer English translation. The developers ...

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