Results 1 to 3 of 3

Thread: QRegExpValidator

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QRegExpValidator

    ok, I know this is silly,

    but I've got a QLineEdit. I want it to take numbers from 0 up to 180.00. A QDoubleValidator isn't exactly the right thing (cos I can still type 12345.6789 and the validator is waiting for a possible 'E-2' say - at least I assume so). So I'm thinking QRegExpValidator.

    I know somebody out there can punch out the regExp really quickly - so what is it?

    any positive number with up to two decimal places up to 180.00.

    sorry to ask but I'll be hours trying to figure it out... I'm starting now anyway
    thanks
    K

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QRegExpValidator

    Well,
    ok there are better ways than this I suppose

    Eg. QRegExp("\\d{0,3}^.\\d{0,2}") to get positive decimals from 0.0 to 999.99

    and then a
    double value = text->toDouble(&ok)
    and asking
    if(value >180.0){
    value = 180.0;
    or
    user message - whatever
    }

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QRegExpValidator

    just to labour the point

    I think
    QRegExp("[0-9]{1,3}\\.?[0-9]{0,2}")
    will take numbers from 0 to 999.99
    using "\\d" instead of [0-9] will accept the minus sign '-' as input

    thanks
    K

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.