Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLineEdit with QDoubleValidator not emitting editingFinished() when e.g. 1,2 insted of 1.2 is entered
Forum Updated to NodeBB v4.3 + New Features

QLineEdit with QDoubleValidator not emitting editingFinished() when e.g. 1,2 insted of 1.2 is entered

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 319 Views 1 Watching
  • 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Hello,
    Title says it all. I've got a QLineEdit with a QDoubleValidator:

    my_lineedit->setValidator(new QDoubleValidator(-DOUBLE_INF, DOUBLE_INF, 10, my_lineedit));
    

    Now when I enter a number with a point ( . ) as decimal point editing finished is emitted and everything works fine.
    However if I enter a comma ( , ) as decimal point the value seems to get accepted. but editing finished is not emitted.
    Why is that. The behavior I want is that the user can enter either a comma or point as they like.

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • gde23G gde23

      Hello,
      Title says it all. I've got a QLineEdit with a QDoubleValidator:

      my_lineedit->setValidator(new QDoubleValidator(-DOUBLE_INF, DOUBLE_INF, 10, my_lineedit));
      

      Now when I enter a number with a point ( . ) as decimal point editing finished is emitted and everything works fine.
      However if I enter a comma ( , ) as decimal point the value seems to get accepted. but editing finished is not emitted.
      Why is that. The behavior I want is that the user can enter either a comma or point as they like.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @gde23 said in QLineEdit with QDoubleValidator not emitting editingFinished() when e.g. 1,2 insted of 1.2 is entered:

      Why is that.

      Because comma is not a decimal point, it's a thousand-separator, in your locale. 1.2 is a full floating point number, 1,2 is not.

      The behavior I want is that the user can enter either a comma or point as they like.

      I don't think Qt offers "alternatives" for decimal point in a locale --- unless someone knows of one which does.

      See https://forum.qt.io/topic/67850/disable-comma-in-qdoublevalidator for thoughts.

      • As @SGaist says there, why are you using a QLineEdit to enter a number when there is a QDoubleSpinBox for floating point number entry and handling text<->number conversions? See also https://stackoverflow.com/questions/42534378/c-qt-creator-how-to-have-dot-and-comma-as-decimal-separator-on-a-qdoubles.
      • You could combine aspects of each of the answers there. E.g. maybe you want QLocale::setNumberOptions(QLocale::RejectGroupSeparator), maybe you want to either reject , or perhaps change it to .. Or try a conversion in two locales, one of which accepts comma as decimal point and another with accepts dot/period.
      1 Reply Last reply
      1
      • gde23G gde23

        Hello,
        Title says it all. I've got a QLineEdit with a QDoubleValidator:

        my_lineedit->setValidator(new QDoubleValidator(-DOUBLE_INF, DOUBLE_INF, 10, my_lineedit));
        

        Now when I enter a number with a point ( . ) as decimal point editing finished is emitted and everything works fine.
        However if I enter a comma ( , ) as decimal point the value seems to get accepted. but editing finished is not emitted.
        Why is that. The behavior I want is that the user can enter either a comma or point as they like.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @gde23

        My only thought about this is building your own QDoubleValidator subclass and handle the validation yourself, by using two different locale versions. One that uses comma and one with a dot.
        Don't know if that works.

        • https://doc.qt.io/qt-6/qdoublevalidator.html#details

        • https://doc.qt.io/qt-6/qlocale.html#toDouble


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        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