I'm a new bie to Qt C++.. I have a QLineEdit. In which i have to Enter only the integers. If i press an Alphabet or any any other character my QLineEdit should not accept it. How to do this in qt with C++? Please Help To solve this.
Asked
Active
Viewed 380 times
1 Answers
3
According to documentation it has already implemented in Qt. You have only to do something like this:
QValidator *validator = new QIntValidator(100, 999, this);
QLineEdit *edit = new QLineEdit(this);
// the edit lineedit will only accept integers between 100 and 999
edit->setValidator(validator);
you can read more here: Int validator

andrea.marangoni
- 1,499
- 8
- 22
-
Thanks a lot... I used a QDoubleValidator where i can make use of the decimal values too.. :-) Thanks a lot... :) – New Moon Dec 10 '12 at 10:57
-
you asked for integers so i suggested *QIntValidator* =) – andrea.marangoni Dec 10 '12 at 10:59