qt 得到主机的IP地址
// 得到主机的IP地址
QString strIpAddress;
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
int nListSize = ipAddressesList.size();
for (int i = 0; i < nListSize; ++i)
{
if ( ipAddressesList.at(i).protocol() == QAbstractSocket::IPv4Protocol )
{
if ( ipAddressesList.at(i) != QHostAddress::LocalHost )
{
strIpAddress = ipAddressesList.at(i).toString();
qDebug(strIpAddress.toLatin1().data());
ui->combLocalIPAddr->addItem(strIpAddress);
}
}
}
联系方式:heshengjun@tinywsn.com