[Qt] How to set QLineEdit with numbers only

Qt has rather indirect way to control input type. “setInputMethodHints” is available, but QLine Widget ignores it.

We need to use QReqExp class for defining “Regular Expressions” , below  is example of regular expression where QLineEdit only takes input in numbers only!

      QRegExp rx("\\d+");
      QLineEdit *edit = new QLineEdit();
      edit->setValidator(validator);
      this->setCentralWidget(edit);

About glframebuffer

just another guy.
This entry was posted in Qt. Bookmark the permalink.

1 Response to [Qt] How to set QLineEdit with numbers only

  1. Natalia says:

    Thank you, this is works perfectly.

Leave a comment