参考1:https://yq.aliyun.com/articles/272274
参考2:https://www.hexcode.cn/article/show/qt-getip
-
借鉴方案(未解决):
由于电脑有多个网络适配连接(2个虚拟机+2个无线网),如图
根据参考1,可以获取到本机的IP相关信息,但是两个无线网无法区别谁是当前IP
// 获取所有网络接口
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
QList<QNetworkAddressEntry> entry;
foreach(QNetworkInterface inter, interfaces)
{
// 过滤掉虚拟机
if(-1 != inter.humanReadableName().indexOf("VMware"))
continue;
if (inter.flags() & (QNetworkInte