QString changyanlong_xiaolaohu::IpAddress() {
QString strIpAddress;
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
// find ipv4 address
int nListSize = ipAddressesList.size();
for (int i = 0; i < nListSize; ++i)
{
if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
ipAddressesList.at(i).toIPv4Address()) {
strIpAddress = ipAddressesList.at(i).toString();
break;
}
}
// if v4 is none , find local ip address
if (strIpAddress.isEmpty())
strIpAddress = QHostAddress(QHostAddress::LocalHost).toString();
return strIpAddress;
}
网友评论