November 2014
Beginner to intermediate
264 pages
5h 32m
English
A common thing you might need to do is localize currencies and dates. Qt makes this easy, although the solution isn't obvious until you've thought about it a bit.
First, you need to know about the QString arg method. It replaces an escaped number with the formatted version of its argument; if we write:
QString s = QString("%1 %2").arg("a").arg("b");Then, s contains the string "a b". Second, you need to know about the toString method of QLocale which formats its argument in a locale-specific way.
So, we could write:
QString currencyValue = QString("%1 %2")
.arg(tr("$")).arg(QLocale::toString(value, 'g', 2)This uses tr to localize the currency symbol and the QLocale class's static method, ...
Read now
Unlock full access