tags:

views:

74

answers:

2

I thought QHostAddress was it, but it strangely does not provide methods for validating whether or not the IP address is valid (anymore, got deprecated to Qt3).

Does anyone know?

+4  A: 

There is an alternative to using isIpv4Address() and isIPv6Address(). For example:

QHostAddress address(myString);
if (QAbstractSocket::IPv4Protocol == address.protocol())
{
   qDebug("Valid IPv4 address.");
}
else if (QAbstractSocket::IPv6Protocol == address.protocol())
{
   qDebug("Valid IPv6 address.");
}
else
{
   qDebug("Unknown or invalid address.");
}

See also:

http://doc.trolltech.com/4.6/qhostaddress.html#protocol

Hope this helps.

RA
Good enough for me. Thank you!
ShaChris23
Strange how Nokia doesn't just make this one of the methods in QHostAddress. I will put a ticket in asking them.
ShaChris23
A: 

Here is the official answer from Nokia support engineer, name removed for privacy protection:

I posted a question on stackoverflow.com as follow:

http://stackoverflow.com/questions/2240530/does-qt-provide-a-class-that-represents-an-ip-address

You can see that someone posted a solution to my question already.

However, I want to ask how come Nokia doesn't just provide a method to

QHostAddress ( like isValid() ) that will check the host address's validity?

Thank you for your inquiry. You can use the isNull() method to check the validity. It will return true for invalid addresses: http://qt.nokia.com/doc/4.6/qhostaddress.html#isNull

Hope this helps.

Regards,

Support Engineer, Qt Development Frameworks, Nokia

ShaChris23