【Qt】QT5 获取IP地址

QT获取本机IP地址

#include <QtNetwork/QHostAddress>
#include <QtNetwork/QNetworkInterface>
#include <QList>
#include <QDebug>
//获取IP地址
void getIP()
{
QList<QHostAddress> list = QNetworkInterface::allAddresses();
foreach (QHostAddress address,list)
{
if(address.protocol() == QAbstractSocket::IPv4Protocol)
{
qDebug()<< address.toString();
}
}
// return "0.0.0.0";
}

QT获取本机主机名称

#include <QtNetwork/QHostInfo> //包含的头文件
QString localHostName = QHostInfo::localHostName();
上一篇:iOS 获取IP地址


下一篇:quick Cocos2dx lua 接anysdk