如何将QHostAddress转换为IPv4格式的QString?
发布于 2013-06-04 10:20:20
使用QHostAddress::toString()。
更新
如果您的QHostAddress实例封装了IPv6地址(即QHostAddress::protocol()返回QAbstractSocket::IPv6Protocol),则必须首先将该地址转换为IPv4地址,然后再将IPv4地址转换为QString
QHostAddress ip6Address;
bool conversionOK = false;
QHostAddress ip4Address(ip6Address.toIPv4Address(&conversionOK));
QString ip4String;
if (conversionOK)
{
ip4String = ip4Address.toString();
}同样值得注意的是,上面的IP6到IP4的转换不能在Qt4的上工作,它只能在Qt5上工作。
https://stackoverflow.com/questions/16908812
复制相似问题