Changing locale in Qt

前端 未结 1 1415
情深已故
情深已故 2020-12-06 17:16

I tried to change locale using QLocale and setDefault function but it seems that it doesn\'t work. Here is example of changing locale using C localization library and QLocal

相关标签:
1条回答
  • 2020-12-06 18:21

    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" 
    
    0 讨论(0)
提交回复
热议问题