qt获取本地ip

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


你可能感兴趣的:(qt)