#include <QtNetwork>
int main()
{
QString localHostName = QHostInfo::localHostName();
qDebug() <<"localHostName:"<<localHostName;
QHostInfo info = QHostInfo::fromName(localHostName);
foreach(QHostAddress address,info.addresses())
{
if(address.protocol() == QAbstractSocket::IPv4Protocol)
qDebug() <<"IPV4 Address: "<< address.toString();
}
}
原文:http://www.cnblogs.com/wlcaption/p/3837302.html