Reputation: 33813
I have a QLineEdit
.
I want when the user enters data in that field allows only to enter the numbers, or allows only to enter the text string, and so on.
I know the method to do that and that by using void QLineEdit::setValidator (const QValidator * v)
, but I don't know how to use this method?
Upvotes: 2
Views: 2537
Reputation: 18504
QRegExp rx("regex");
QValidator *validator = new QRegExpValidator(rx, this);
QLineEdit *edit = new QLineEdit(this);
edit->setValidator(validator);
Where regex for string:
[a-zA-Z]+
For numbers:
[0-9]+
Upvotes: 6