How many validators can be applied to a single QLineEdit?
I have a QLineEdit in a dialog box I am creating that allows entering an IP address. I have used a QRegExp validator to ensure that it takes the form:
"[0-2][0-9][0-9][.][0-2][0-9][0-9][.][0-2][0-9][0-9][.][0-2][0-9][0-9]"
(I know I need some improvement with regular expressions...:D)
This works ok but I still need to range check so each of the four values are within 0-255.
Can multiple validators be applied to the same widget?
Or, am I going about this all wrong?
I was thinking it might be better to break down the QLineEdit into four separate ones, use the range checking of a QIntValidator and then convert to one single QString after it is valid?
Re: How many validators can be applied to a single QLineEdit?
Quote:
Originally Posted by
awhite1159
This works ok but I still need to range check so each of the four values are within 0-255.
You can achieve this with a regular expression.
Quote:
Originally Posted by
awhite1159
Can multiple validators be applied to the same widget?
No, but you can create a CompositeValidator class that will aggregate several validators.
Re: How many validators can be applied to a single QLineEdit?
Thanks Jacek.
As I said, I need to improve my regular expressions knowledge. Time to pull out my O'Reilly AWK reference and read up on regular expressions.
Re: How many validators can be applied to a single QLineEdit?
Quote:
Originally Posted by
awhite1159
Time to pull out my O'Reilly AWK reference and read up on regular expressions.
See this one: http://regex.info/
Re: How many validators can be applied to a single QLineEdit?
Got it:
QRegExp rx("(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]?)");
(All on a single line.)