qt获取本地IP
#include <QtNetwork>
int main()
{
QString localHostName = QHostInfo::localHostName();
qDebug() <<"localHostName:"<<localHostName;
QHostInfo info = QHostInfo::fromName(localHostName);
foreach(QHostAddress address,info.addresses())
{
if(address.protocol() == QAbstractSocket::IPv4Protocol)
qDebug() <<"IPV4 Address: "<< address.toString();
}
}