Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-83415

QLocale::setDefault without effect for number options

XMLWordPrintable

    • macOS
    • c7420d9cb8e15d1f094fa92cfab635a86246c670 (qt/qtbase/dev) c39dbabde9d98b805f1d1884d3aeee5c8dcb4d03 (qt/qtbase/5.15)

      The QLocale::setDefault function seems to have no effect, at least with number options. I didn't test other options yet. This affects the default construction of a QLocale object as well as QString::arg. See the example code (also attached as project), which doesn't output what is expected according to the documentation.

      Example code:

      // setup a custom locale
      QLocale customLocale( QLocale::English );
      customLocale.setNumberOptions( QLocale::OmitGroupSeparator | QLocale::OmitLeadingZeroInExponent |
                                     customLocale.numberOptions() );
      
      // Set the custom locale as default
      // https://doc.qt.io/qt-5/qlocale.html#setDefault
      QLocale::setDefault( customLocale );
      
      // using the custom locale directly
      // https://doc.qt.io/qt-5/qlocale.html#toString-8
      QString str1 = customLocale.toString( d );
      qDebug() << str1;
      
      // using the default locale which was set to be the custom locale is supposed to give the same output!
      // https://doc.qt.io/qt-5/qlocale.html#QLocale
      QLocale loc;
      QString str2 = loc.toString( d );
      qDebug() << str2;
      
      // Arg is also supposed to use the default locale according to its documentation.
      // https://doc.qt.io/qt-5/qstring.html#arg-9
      QString str3 = QString( "%1" ).arg( d );
      qDebug() << str3;

      Output:

      "5e-7"
      "5e-07"
      "5e-07"
      

      Expected:

      "5e-7"
      "5e-7"
      "5e-7"
      

      Note that with Qt 5.9.1 the output is as expected!

      Note: I could only test this using the Xcode platform SDK 10.13 and 10.15, with which Qt 5.14.2 outputs warnings about being not officially supported.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Eddy Edward Welbourne
            boernsen boernsen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes