简体   繁体   中英

How to tell if QHostAddress is IPv4 or IPv6 in Qt5?

I can create a QHostAddress objects like this:

QHostAddress addr_ip4("127.0.0.1");
QHostAddress addr_ip6("::1/128");

And test their properties like this:

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();

But... how can I tell which of the addresses are in fact IPv4 and which are IPv6 ?

调用QHostAddress :: protocol()将返回QAbstractSocket :: NetworkLayerProtocol枚举 ,该枚举指定地址是IPv4,IPv6还是两者。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM