Changing locale in Qt

QLocale::setDefault() does not change the system locale. It changes what QLocale object created with default constructor is.

Supposedly, system locale can only be changed via system control panel/preferences by the user. If you want to format something that is not in the system locale, you need to specifically do that with a locale object.

This code:

QLocale curLocale(QLocale("pl_PL"));
QLocale::setDefault(curLocale);
QDate date = QDate::currentDate();
QString dateString = QLocale().toString(date);
qDebug() << dateString;
qDebug() << QLocale().name();

Prints this:

"piÄ…tek, 9 listopada 2012" 
"pl_PL" 

Leave a Comment