int 型 IPv4 值转换为 IPv4 字符串:
1 QString IPV4IntegerToString(quint32 ip) { 2 return QString("%1.%2.%3.%4") 3 .arg((ip >> 24) & 0xFF) 4 .arg((ip >> 16) & 0xFF) 5 .arg((ip >> 8) & 0xFF) 6 .arg(ip & 0xFF); 7 }
IPv4 字符串转换为 int 型 IPv4 值:
1 quint32 IPV4StringToInteger(const QString& ip){ 2 QStringList ips = ip.split("."); 3 if(ips.size() == 4){ 4 return ips.at(3).toInt() 5 | ips.at(2).toInt() << 8 6 | ips.at(1).toInt() << 16 7 | ips.at(0).toInt() << 24; 8 } 9 return 0; 10 }
转自:https://blog.csdn.net/wangmike19/article/details/102501684
原文地址:https://www.cnblogs.com/liushui-sky/p/12168626.html
时间: 2024-10-05 05:04:51