How would one set an input validator on a QLineEdit such that it restricts it to a valid IP address? i.e. x.x.x.x where x must be between 0 and 255.
How would one set an input validator on a QLineEdit such that it restricts it to a valid IP address? i.e. x.x.x.x where x must be between 0 and 255.
Last edited by DiamonDogX; 14th August 2009 at 20:10.
Input masks are not sufficient for that. You need a validator. Refer to the wiki for details.
you need to use QRegExpValidator with a regexp accepting the IP address (I did it like this but not sure if it works perfectly :P):
Qt Code:
QRegExp rx("((1{0,1}[0-9]{0,2}|2[0-4]{1,1}[0-9]{1,1}|25[0-5]{1,1})\\.){3,3}(1{0,1}[0-9]{0,2}|2[0-4]{1,1}[0-9]{1,1}|25[0-5]{1,1})"); v->setRegExp(rx); ui->lineEdit->setValidator(v);To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
tituslup (3rd November 2009)
Bookmarks