Results 1 to 3 of 3

Thread: QRegExp for validating a float entered ina lineEdit

  1. #1
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default QRegExp for validating a float entered ina lineEdit

    Hi,
    I want to read a number in the rangue [0; 20] with one "decimal" precision.
    Examples:
    0
    1.5
    12.4
    14
    20

    I'm using ...
    Qt Code:
    1. ...
    2. QRegExp regExp("[0-9]{1,1}|1[0-9]{1,1}|20");
    3. lineEdit_t1->setValidator(new QRegExpValidator(regExp, this));
    4. ...
    To copy to clipboard, switch view to plain text mode 

    This validates integer only but is there a shorter way?
    What if i want to extend it for the numbers in the example above?

    I supose i could use input masks or something but i am trying the regular expressions.

    Thanks

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegExp for validating a float entered ina lineEdit

    Why not to use QDoubleValidator ?

  3. #3
    Join Date
    Jan 2009
    Posts
    78
    Thanks
    21
    Thanked 1 Time in 1 Post

    Default Re: QRegExp for validating a float entered ina lineEdit

    Because i didn't knew that one yet
    Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.