分类: C/C++
2011-10-19 17:51:08
QString GetLocalIPAddress()
{
QString vAddress;
#ifdef _WIN32
QHostInfo vHostInfo = QHostInfo::fromName(QHostInfo::localHostName());
QList
#else
QList
#endif
for(int i = 0; i < vAddressList.size(); i++)
{
if(!vAddressList.at(i).isNull() &&
vAddressList.at(i) != QHostAddress::LocalHost &&
vAddressList.at(i).protocol() == QAbstractSocket::IPv4Protocol)
{
vAddress = vAddressList.at(i).toString();
break;
}
}
return vAddress;
}
在XP系统中如果使用以下方法 ,在函数返回时将回报错,当然不一定是所有机器都这样
QList