1, header files
#include<QHostAddress>
#include<QNetworkInterface>
2, the code
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 QList<QHostAddress> list = QNetworkInterface::allAddresses(); 2 foreach(QHostAddress address, list) 3 { 4 //qDebug()<<address.toString(); 5 if(address.protocol() == QAbstractSocket::IPv4Protocol) 6 { 7 qDebug()<<address.toString(); 8 } 9 }