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

Default Qt.locale() can't parse a valid number string

    XMLWordPrintable

Details

    • Linux/X11

    Description

      import QtQml 2.15
      
      QtObject {
          property double value: Number.fromLocaleString("1,234.01") // 1) Does not work, system locale is en_US
          // property double value: Number.fromLocaleString(Qt.locale(), "1,234.01") // 2) Does not work, system locale is en_US
          // property double value: Number.fromLocaleString(Qt.locale(Qt.locale().name), "1,234.01") // 3) WORKS!
      
          onValueChanged: console.log("value:", value)
      
          Component.onCompleted: {
              console.log("Default locale:", Qt.locale().name, ", uiLanguages:", Qt.locale().uiLanguages[0])
          }
      }
      

      Output:

      qml: Default locale: en_US , uiLanguages: en-US
      file:///home/user/work/projects/test/test_number_default_locale.qml:4: Error: Locale: Number.fromLocaleString(): Invalid format
      

      Expected output:

      qml: value: 1234.01
      qml: Default locale: en_US , uiLanguages: en-US
      

      If I instantiate Qt.locale using default locale name, it works as expected:

      property double value: Number.fromLocaleString(Qt.locale(Qt.locale().name), "1,234.01")
      

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            rightaway717 Ivan Belyakov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes