more flexible SetMaskInput
-
Hello,
I would like to make a mask input in a line edit for an IP address. Most often I find the suggestion
mylineEdit->setInputMask("000.000.000.000");
But if I enter an IP address like 192.168.0.100 it would look like 192.168.0 .100 with two spaces in it.
Is there a way to avoid that?
I would appreciate any help! Thank you -
Hello,
I would like to make a mask input in a line edit for an IP address. Most often I find the suggestion
mylineEdit->setInputMask("000.000.000.000");
But if I enter an IP address like 192.168.0.100 it would look like 192.168.0 .100 with two spaces in it.
Is there a way to avoid that?
I would appreciate any help! Thank you@NinaWeber
use QRegExpValidator (Qt4) or QRegularExpressionValidator (Qt5)
with the following regexp:"25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
or less accurate:
"(?:[0-9]{1,3}\.){3}[0-9]{1,3}"