Results 1 to 8 of 8

Thread: QDoubleValidator

  1. #1
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QDoubleValidator

    Hi all,

    I am using the QDoubleValidator to validate a QLineEdit field that must contain 10 numerical digits, I am trying thus more without success.

    QValidator *doupleValidatorTell = new QDoubleValidator(0, 1, 9, this); /* allowed to type (10 digits) */
    txtTest->setValidator(doupleValidatorTell);

    Cris

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDoubleValidator

    It doesn't allow to type 10 digits... It'll accept entries from 0.000000001 to 1.000000000. Is that what you want?

  3. #3
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDoubleValidator

    No.

    I only want that it can be typed 10 digits and nothing more for example, "4533336807"

    In the case of 8 digits use the QIntValidator, thus:

    QIntValidator *intValidatorNum = new QIntValidator(0, 99999999, this); /* allowed to type (8 digits) */
    txtNum->setValidator(intValidatorNum);

    Cris

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDoubleValidator

    So why do you use a double validator?

  5. #5
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QDoubleValidator

    More with QIntValidator I do not obtain uses more than 10 digits, only 9, more than what this of the error.

    In case that I acrecente more 2 digits “9999999999”

    QIntValidator *intValidatorNum = new QIntValidator(0, 9999999999, this);

    The compiler prints the error.

    "src/XForm/Form.cpp:90: error: integer constant is too large for "long" type"

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDoubleValidator

    Signed integer type can hold a maximum of ~2G on 32bit machines, unsigned can hold up to ~4G. If you need longer numbers, I suggest you validate strings (for instance with QRegExpValidator with a regexp of \d{0,10} expression.

  7. #7
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDoubleValidator

    Quote Originally Posted by wysota View Post
    So why do you use a double validator?

    qft. QRegExpValidator sounds more like what you are looking for.

  8. #8
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Talking Re: QDoubleValidator

    Friends, now functioned !!!

    Qt Code:
    1. QRegExp rx( "-?\\d{0,10}" ); /* allowed to type (10 digits) */
    2. QValidator* validatorNum = new QRegExpValidator( rx, this );
    3. txtNum->setValidator(validatorNum);
    To copy to clipboard, switch view to plain text mode 

    thanks,

    Cris
    Last edited by wysota; 19th January 2007 at 21:19. Reason: missing [code] tags

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.