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);
            }
        }
     }
posted @ 2018-02-03 15:47  未命名blogs  阅读(278)  评论(0编辑  收藏  举报