Results 1 to 5 of 5

Thread: QIntValidator input

  1. #1
    Join Date
    Jun 2007
    Location
    Wrocław, Poland
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QIntValidator input

    Hi there
    I'm not sure if it's something's wrong with QIntValidator class, or with my code. I use this class as below:
    Qt Code:
    1. QIntValidator *gV = new QIntValidator(0, 500, this);
    2. gravityEdit = new QLineEdit(QString("%1").arg(parentWindow->scene->gravityForce.g), this);
    3. gravityEdit->setValidator(gV);
    To copy to clipboard, switch view to plain text mode 

    Now when I launch the application and edit 'gravityEdit', validator works, but it accepts input from 0 to 999. Any ideas when did I go wrong? It looks like it sets input range maximum to powers of 10 only, but i want it to be 0 - 500, is it possible?

  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: QIntValidator input

    What happens after you leave the field or press return after typing in "999"?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QIntValidator input

    QSpinBox would make it simple. It's basically a specialized line edit designed especially for numerical input.
    J-P Nurmi

  4. #4
    Join Date
    Jun 2007
    Location
    Wrocław, Poland
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QIntValidator input

    Quote Originally Posted by wysota View Post
    What happens after you leave the field or press return after typing in "999"?
    Everything works like it was an accetable input...the value is just set to "999", like there was no validator :/

    Quote Originally Posted by jpn View Post
    QSpinBox would make it simple. It's basically a specialized line edit designed especially for numerical input.
    You're right, I thought about using QSpinBox , but i'm just curious is it bug in QIntValidator, or just my mistake

  5. #5
    Join Date
    Jun 2007
    Location
    Wrocław, Poland
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QIntValidator input

    Ok, problem solved. My mistake was that I didn't use hasAcceptableInput() function to check if the input is Acceptable, before making any changes. Using validate() function to check the states of validator shows that for 500-999 it's Intermediate, that's why it was possible to enter that values from that range. And without a "guard" like hasAcceptableInput(), this input could be passed by textEdited(const QString &) signal.

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.