Qt-interest Archive, December 2007
re: Validate QEditBox - ip address or hostname (3.3)
Message 1 in thread
I need to validate whether an edit box contains an IP address or a string
(hostname).
How do I go about doing this?
Message 2 in thread
This really isn't a QT issue...
You get the string the edit box contains (I assume, buy edit box you
have a QLineEdit) via the QLineEdit::text() method, then you run the
algorithm your business logic desires on the string to determine if it's
a valid IP addres or hostname
Scott
________________________________
From: Ann Marie [mailto:annmarieqt@xxxxxxxxx]
Sent: Sunday, December 16, 2007 4:23 PM
To: Qt Interest List
Subject: re: Validate QEditBox - ip address or hostname (3.3)
I need to validate whether an edit box contains an IP address or a
string (hostname).
How do I go about doing this?
Message 3 in thread
You could use regular expressions to check whether it is an ip address or not. Mind you, you might have to make the distinction between ip4 and ip6 addresses. If it is not an ip address then you can assume it is a host name.
An example of regular expression for ip4 addresses is: ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}) . I added the parentheses so you can get the actual numbers that compose the ip address and then make sure they are between 0 and 255. Qt regular expressions support grouping (check out the QRegExp::cap function).
Another idea is to use masks but you'll probably need to add a radio button.
B.
"Scott Aron Bloom" <Scott.Bloom@xxxxxxxxxxxx> wrote in message news:7DB34253D57D2B47AEB656218FE6AAEF03BA05@xxxxxxxxxxxxxxxxxxxxxxxxx
This really isn't a QT issue.
You get the string the edit box contains (I assume, buy edit box you have a QLineEdit) via the QLineEdit::text() method, then you run the algorithm your business logic desires on the string to determine if it's a valid IP addres or hostname
Scott
------------------------------------------------------------------------------
From: Ann Marie [mailto:annmarieqt@xxxxxxxxx]
Sent: Sunday, December 16, 2007 4:23 PM
To: Qt Interest List
Subject: re: Validate QEditBox - ip address or hostname (3.3)
I need to validate whether an edit box contains an IP address or a string (hostname).
How do I go about doing this?
Message 4 in thread
On søndag den 16. December 2007, Ann Marie wrote:
> I need to validate whether an edit box contains an IP address or a string
> (hostname).
>
> How do I go about doing this?
Look at QValidator in assistant. You can either code your own, or use a
QRegExpValidator together with the regular expression B.C. posted in another
answer.
Bo.
--
[ signature omitted ]