Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does tr("\302\261") mean in Qt?

Tags:

c++

qt

I was following Qt Calculator example from http://doc.qt.io/qt-5/qtwidgets-widgets-calculator-example.html. I encountered the code below.

for (int i = 0; i < NumDigitButtons; ++i) {
    digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked()));
}

Button *pointButton = createButton(tr("."), SLOT(pointClicked()));
Button *changeSignButton = createButton(tr("\302\261"), SLOT(changeSignClicked()));

Button *backspaceButton = createButton(tr("Backspace"), SLOT(backspaceClicked()));
Button *clearButton = createButton(tr("Clear"), SLOT(clear()));
Button *clearAllButton = createButton(tr("Clear All"), SLOT(clearAll()));

Button *clearMemoryButton = createButton(tr("MC"), SLOT(clearMemory()));
Button *readMemoryButton = createButton(tr("MR"), SLOT(readMemory()));
Button *setMemoryButton = createButton(tr("MS"), SLOT(setMemory()));
Button *addToMemoryButton = createButton(tr("M+"), SLOT(addToMemory()));

Button *divisionButton = createButton(tr("\303\267"), SLOT(multiplicativeOperatorClicked()));
Button *timesButton = createButton(tr("\303\227"), SLOT(multiplicativeOperatorClicked()));
Button *minusButton = createButton(tr("-"), SLOT(additiveOperatorClicked()));
Button *plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked()));

Button *squareRootButton = createButton(tr("Sqrt"), SLOT(unaryOperatorClicked()));
Button *powerButton = createButton(tr("x\302\262"), SLOT(unaryOperatorClicked()));
Button *reciprocalButton = createButton(tr("1/x"), SLOT(unaryOperatorClicked()));
Button *equalButton = createButton(tr("="), SLOT(equalClicked()));

However, I couldn't understand what do tr("\302\261") ,tr("\303\267"), tr("x\302\262")mean from the lines below.

Button *changeSignButton = createButton(tr("\302\261"), SLOT(changeSignClicked()));
Button *divisionButton = createButton(tr("\303\267"), SLOT(multiplicativeOperatorClicked()));
Button *powerButton = createButton(tr("x\302\262"), SLOT(unaryOperatorClicked()));

When I removed \303\267, I found ÷ symbol disappears. So I guess it is somehow related to division button.

I have no idea how \303\267 can be related to division. I searched Qt documentation page, and found nothing.

My question is:

What do tr("\302\261") ,tr("\303\267"), and tr("x\302\262") mean in this example?

like image 578
David Avatar asked Mar 03 '18 22:03

David


Video Answer


1 Answers

tr() function is used for (optional) translation of given string to another languages. From this answer available on Qt forum:

If you want your application to have multiple language support, wrap every user-visible string in your code inside a tr() function. Then Qt will use the appropriate translated string in a different language environment. Of course Qt won't actually translate for you, you (or your translator guy) have to do that with QtLinguist.

The strings passed to tr() function are octal codes for UTF-8 characters. As you have noticed, \303\267 is ÷. \302\261 is ±, x\302\262 means x to power of two (x followed by superscript two character).

like image 157
Artur Rychlewicz Avatar answered Nov 15 '22 03:11

Artur Rychlewicz