获取本机网络信息

QList<QHostAddress> list = QNetworkInterface::allAddresses();

QString locaHostName = QHostInfo::localHostName();
qDebug() << locaHostName;
QHostInfo info = QHostInfo::fromName(locaHostName);
qDebug() << "IP Address:" << info.addresses();
foreach(QHostAddress address, list)
{
if (address.protocol() == QAbstractSocket::IPv4Protocol)
{
qDebug() << address.toString();
return;
}
}

posted @ 2016-07-19 20:05  TheSongOfSoul  阅读(198)  评论(0编辑  收藏  举报