level 4
bool GetLocalIP(QString & IP)
{
QList<QNetworkInterface> mList=QNetworkInterface::allInterfaces();
if(mList.count()>0) { foreach(QNetworkInterface inf,mList) { QList<QNetworkAddressEntry> eList=inf.addressEntries(); foreach(QNetworkAddressEntry ent,eList) { QHostAddress ha=ent.ip(); if(!ha.isNull()&&ha.protocol()==QAbstractSocket::IPv4Protocol) { IP=ha.toString(); break; } } if(IP.isEmpty()||IP=="") continue; else break; } if(IP.isEmpty()||IP=="") return false; else return true; } else { return false; }}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/scutLiu/archive/2010/08/17/5818945.aspx
2011年03月16日 10点03分
1
{
QList<QNetworkInterface> mList=QNetworkInterface::allInterfaces();
if(mList.count()>0) { foreach(QNetworkInterface inf,mList) { QList<QNetworkAddressEntry> eList=inf.addressEntries(); foreach(QNetworkAddressEntry ent,eList) { QHostAddress ha=ent.ip(); if(!ha.isNull()&&ha.protocol()==QAbstractSocket::IPv4Protocol) { IP=ha.toString(); break; } } if(IP.isEmpty()||IP=="") continue; else break; } if(IP.isEmpty()||IP=="") return false; else return true; } else { return false; }}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/scutLiu/archive/2010/08/17/5818945.aspx