PDA

View Full Version : IP address input mask?



DiamonDogX
14th August 2009, 20:42
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.

wysota
14th August 2009, 20:47
Input masks are not sufficient for that. You need a validator. Refer to the wiki for details.

faldzip
15th August 2009, 08:54
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):


QRegExpValidator *v = new QRegExpValidator(this);
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);