QT 进行网络监测----获取本地IP

         获取本地IP地址,排除127回环:

QString MainWindow::getLocalIP()
{

   QList<QHostAddress> list = QNetworkInterface::allAddresses();
   foreach (QHostAddress address, list)
   {
       //使用IPv4地址
       if(address.protocol() == QAbstractSocket::IPv4Protocol)
       {
           if (address.toString().contains("127.0."))
            {
               //qDebug()<<address.toString();
               continue;
            }
           else
           {
           //qDebug()<<address.toString();
           return address.toString();
			}
     }
   }
   return 0;
}





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