我可以像这样创建QHostAddress
个对象:
QHostAddress addr_ip4("127.0.0.1");
QHostAddress addr_ip6("::1/128");
并测试他们的属性:
qDebug() << "addr_ip4.isNull() = " << addr_ip4.isNull();
qDebug() << "addr_ip4.isLoopback() = " << addr_ip4.isLoopback();
qDebug() << "addr_ip4.isMulticast() = " << addr_ip4.isMulticast();
qDebug() << "addr_ip6.isNull() = " << addr_ip6.isNull();
qDebug() << "addr_ip6.isLoopback() = " << addr_ip6.isLoopback();
qDebug() << "addr_ip6.isMulticast() = " << addr_ip6.isMulticast();
但是......我怎么知道哪个地址实际上是 IPv4 哪个 IPv6 ?
答案 0 :(得分:5)
调用QHostAddress::protocol()将返回QAbstractSocket::NetworkLayerProtocol enum,指定地址是IPv4,IPv6,还是其他地址。