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. Let's try it out.
- You need to know about the QString arg method. This replaces an escaped number with the formatted version of its argument. For example, if we write the following:
QString s = QString("%1 %2").arg("a").arg("b");
Then, s will contain the string "a b".
- You need to know about the toString method of QLocale, which formats its argument in a locale-specific way. So, we could write the following:
QString currencyValue = QString("%1 %2") .arg(tr("$")).arg(QLocale::toString(value, 'g', 2)
This uses tr to localize the currency symbol and the QLocale...