PDA

View Full Version : QIntValidator input



chaos_theory
18th August 2007, 15:35
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:


QIntValidator *gV = new QIntValidator(0, 500, this);
gravityEdit = new QLineEdit(QString("%1").arg(parentWindow->scene->gravityForce.g), this);
gravityEdit->setValidator(gV);


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?

wysota
18th August 2007, 16:06
What happens after you leave the field or press return after typing in "999"?

jpn
18th August 2007, 16:12
QSpinBox would make it simple. ;) It's basically a specialized line edit designed especially for numerical input.

chaos_theory
18th August 2007, 16:25
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 :/


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;)

chaos_theory
19th August 2007, 11:28
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.