Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. DoubleValidator strange behavior
Qt 6.11 is out! See what's new in the release blog

DoubleValidator strange behavior

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 549 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    f-ij
    wrote on last edited by
    #1

    I'm using QML and I need textfields that only accept doubles. I used DoubleValidator for this. However, when I enter, for example a 0.2 in the textfield and hit tab, it will change the value to 2. The same holds for any number formatted as "0.00...0x". When I write any other number after the x, though, it will work correctly. I have no idea why this is and why anyone would want this. What am I doing wrong?

    GrecKoG 1 Reply Last reply
    0
    • F f-ij

      I'm using QML and I need textfields that only accept doubles. I used DoubleValidator for this. However, when I enter, for example a 0.2 in the textfield and hit tab, it will change the value to 2. The same holds for any number formatted as "0.00...0x". When I write any other number after the x, though, it will work correctly. I have no idea why this is and why anyone would want this. What am I doing wrong?

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @f-ij Which locale are you using? In some country like France the period is just a separator for thousands and it's the comma that is used as a decimals marker.

      You can force a locale on your DoubleValidator if you don't want to use the system one: locale: "en"

      F 1 Reply Last reply
      1
      • GrecKoG GrecKo

        @f-ij Which locale are you using? In some country like France the period is just a separator for thousands and it's the comma that is used as a decimals marker.

        You can force a locale on your DoubleValidator if you don't want to use the system one: locale: "en"

        F Offline
        F Offline
        f-ij
        wrote on last edited by f-ij
        #3

        @GrecKo said in DoubleValidator strange behavior:

        locale: "en"

        Thanks so much, this was indeed the problem! I suspected something like this at some point, and tried using a comma as a separator, but this wasn't accepted due to me using the parseFloat function somewhere in my code, which I mistakenly took as validation that commas weren't the right separator in the DoubleValidator.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved