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. [Solved]QDoubleValidator: How to reject comma as decimal point?

[Solved]QDoubleValidator: How to reject comma as decimal point?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.4k 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.
  • C Offline
    C Offline
    chris17
    wrote on last edited by
    #1

    Hi,

    in my application I want to avoid that numbers are entered with a comma as decimal point.

    code for the validator:
    @
    QDoubleValidator v;
    QLocale loc=QLocale::c();
    loc.setNumberOptions(QLocale::RejectGroupSeparator | QLocale::OmitGroupSeparator);
    v.setLocale(loc);
    @

    The problem is that the validator accepts both "1.23" and "1,23".

    Am I doing sth wrong or might this be a bug in Qt?

    I'm using Qt 4.8.4.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      marceloarguello700
      wrote on last edited by
      #2

      I know that is a late answer, but will be usefull for someone with the same need.
      i resolve with QRegExpValidator
      @
      lineEdit->setValidator(new QRegExpValidator(QRegExp("[-]{0,1}\d{0,}\.\d{0,}"),0) );
      @
      it work for me, only accept one dot.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chris17
        wrote on last edited by
        #3

        I solved it with QRegExpValidator, too.

        Here's my version:
        @QRegExpValidator validator=new QRegExpValidator(QRegExp("^\-?\d\.?\d*(e\-?\d*)?$", Qt::CaseInsensitive),parent);
        lineEdit->setValidator(validator);@

        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