All the way back in Chapter 1, Getting Started with Qt Creator, I told you to always mark your strings for localization using the tr
and qsTr
functions: tr
for C++ and qsTr
for QML strings. Doing so has two key advantages:
Let's examine the use of tr
in more detail. All Qt objects that include the Q_OBJECT
macro in their declaration include the tr
function. You've seen it with one argument, as follows:
button = new QPushButton(tr("&Quit"), this);
The leading &
in the string isn't for the tr
function, but it is for the keyboard accelerators; you can prefix a letter with &
to assign a keyboard accelerator and it gets the default system (a key combination with Alt for Windows, Command for Apple...