QValidator manual validation.
-
Hi,
I got problem with manual validation of handled text.I got situation where I take validator for QLineEdit::validator() and I want to check if my current text is passing validators conditions.
For e.g.
1)I set validatorthis->edit1->setValidator(new QRegExpValidator(QRegExp("[A-Za-z]{5}"),this));//no more than 5 letter character
2)When I try to access this validator from the pointer to QlineEdit and execute QValidator::validate(text, pos(0))
for:- "a" i get QValidator::Intermediate (should be QValidator::Acceptable)
- "aa" I get QValidator::Intermediate (should be QValidator::Acceptable)
- "aaa" I get QValidator::Intermediate (should be QValidator::Acceptable)
- "aaaa" I get QValidator::Intermediate (should be QValidator::Acceptable)
- "aaaaa" I get QValidator::Invalid (should be QValidator::Acceptable)
Do I get something wrong?
How to use that validation?
If I not able to validate handled text by this method could anyone say how can I do that?Best regards,
Tomek -
{5}
means "exactly 5 times" so the fist 4 strings will be partial matches (intermediate state).
to have "no more than 5" use{0,5}
.As for the last case - it returns
Acceptable
to me as expected. Can you show the code that callsvalidate()
? Also what istext
andpos(0)
?As a side note - you should switch to QRegularExpressionValidator if possible. It uses the recommended, Perl compatible, replacement of QRegExp - QRegularExpression.
-
@Kaluss said:
but do You maybe know whats that parameter really do?
It's suppose to be "cursor position", but in case of regexp validator it's really a useless parameter to satisfy the interface of QValidator. It gets set to the length of the string if the regexp validator doesn't find a match.