获取本地ip

QString Widget::getIp()
{
    QString ip;
    QList<QHostAddress> list = QNetworkInterface::allAddresses();
        foreach (QHostAddress address, list)
        {
            if(address.protocol() == QAbstractSocket::IPv4Protocol)
            {
                //IPv4地址
                if (address.toString().contains("192.168.0.") || address.toString().contains("192.168.1."))
                {
                    ip = address.toString();
                    qDebug()<<ip;
                    return ip;
                }
            }
        }
}
 

你可能感兴趣的:(网络,qt,qt,qt)