View Full Version : QDoubleValidator
cristiano
19th January 2007, 12:43
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
wysota
19th January 2007, 12:46
It doesn't allow to type 10 digits... It'll accept entries from 0.000000001 to 1.000000000. Is that what you want?
cristiano
19th January 2007, 13:04
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
wysota
19th January 2007, 14:17
So why do you use a double validator?
cristiano
19th January 2007, 14:32
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"
wysota
19th January 2007, 14:39
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.
Methedrine
19th January 2007, 14:39
So why do you use a double validator?
qft. QRegExpValidator sounds more like what you are looking for.
cristiano
19th January 2007, 21:10
Friends, now functioned !!!
QRegExp rx( "-?\\d{0,10}" ); /* allowed to type (10 digits) */
QValidator* validatorNum = new QRegExpValidator( rx, this );
txtNum->setValidator(validatorNum);
thanks,
Cris
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.