QLocale().toString in french canadian



  • Hello,
    i'm translating my app and trying to display number in the locale of the user. So I use

    QLocale().toString( aValue, 'f', mDecimals )

    If the locale is
    QLocale( QLocale::French, QLocale::France ) the numbers are displayed correctly ( colon before the decimals), however, its the locale is QLocale( QLocale::French, QLocale::Canada), the numbers are displayed using english settings. Is this a bug or am I misusing the toString function?

    Thanks


  • Lifetime Qt Champion

    Hi,

    Can you show how you create the QLocale object and use the numbers with it ?



  • Hi, I keep the default locale, so its just like the example in my previous post (aValue is a float or a double) :

    QLocale().toString( aValue, 'f', mDecimals )
    

    or

    QLocale().toString( aValue )
    

    Right now, i'm using this as a workaround :

    if( QLocale().language() == QLocale::French )
    {
        QLocale lLocale = QLocale( QLocale::French, QLocale::France ) ;
        QLocale::setDefault( lLocale );
    }

  • Lifetime Qt Champion

    I have twice the same result when doing:

    qDebug() << QLocale(QLocale::French, QLocale::France).toString(12.21, 'f', 3);
    qDebug() << QLocale(QLocale::French, QLocale::Canada).toString(12.21, 'f', 3);
    

    return the same output.

    What exact version of Qt, OS and compiler are you using ?



  • Sorry for the delay, I was in hollyday.

    Qt5.7, windows 7, msvc 2013

    EDIT :
    I did a bit more testing.

    qDebug() << QLocale(QLocale::French, QLocale::France).toString(12.21, 'f', 3);
    qDebug() << QLocale(QLocale::French, QLocale::Canada).toString(12.21, 'f', 3);

    Works fine.

    However,

    auto a = QLocale().countryToString( QLocale().country() ); //Canada
    auto b = QLocale().languageToString( QLocale().language() ); //French
    QLocale().toString( 6.3, 'f', 1 ); // => 6.3
    

    Doesnt work and

    auto a = QLocale().countryToString( QLocale().country() ); //France
    auto b = QLocale().languageToString( QLocale().language() ); //French
    QLocale().toString( 6.3, 'f', 1 ); // => 6,3
    

    works correctly


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.