Qt获取本机IP地址

Qt获取本机IP地址:

Qt版本:4.8.6

复制代码
#include <QtNetwork/QNetworkInterface.h>

    QString ipAddr;
    QList<QHostAddress> list = QNetworkInterface::allAddresses();
    foreach (QHostAddress address, list) {
        if (address.protocol() == QAbstractSocket::IPv4Protocol) {
            ipAddr = address.toString();
            break;
        }
    }
复制代码

 

参考:

http://blog.csdn.net/jdh99/article/details/6679692

posted @   onemuji  阅读(1059)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示