QHostAddress 获取ip地址后 格式为"::ffff:127.0.0.1"问题

socket建立以后,获取远端的IP地址,结果格式为  "::ffff:127.0.0.1" 类型, 想要去除前面前缀 ::ffff:

搜索到可以通过设置flags,  QHostAddress::ConvertV4MappedToIPv4, 但是没找到对应的方法.

可以使用规避的方式,先将ip地址格式固定为IPv4模式,然后再返回.

QString convert_to_ipv4_addr(QHostAddress &addr)
{
    quint32  addr_origin = addr.toIPv4Address();
    QHostAddress addr_host = QHostAddress(addr_origin);
    QString  addr_str = addr_host.toString();
    return addr_str;
}
原文地址:https://www.cnblogs.com/rohens-hbg/p/13753703.html