PDA

View Full Version : Use of QValidator in QLineEdit



giorgik
13th June 2012, 11:57
Hello everyone, I have a question about the use of QValidator in QLineEdit:


QRegExp rx("^[1-9]{1, 3}$");
QLineEdit *lineedit = new QLineEdit(this);
lineedit->setValidator(new QRegExpValidator(rx, lineedit));

The widget will not let me enter any numbers, why?
I expected at least to enter a number between 1 and 999, but nothing.
What's missing?

mentalmushroom
13th June 2012, 12:49
use QIntValidator

giorgik
13th June 2012, 17:20
Yes mentalmushroom, works with QIntValidator but I wanted to use QRegExpValidator...

wysota
13th June 2012, 17:38
What if you use {0,3} and not {1,3}? Also skip "^" and "$", they are not required here.

giorgik
14th June 2012, 10:18
I then found out where wrong:

{1, 3} I put a space after the character ','. the correct form is
{1,3}

mentalmushroom
14th June 2012, 10:25
keep in mind this won't let you enter numbers that contain zeros, e.g. 109.