• 4833阅读
  • 0回复

[讨论]QHostInfo::lookupHost为甚么只能返回一个IP? [复制链接]

上一主题 下一主题
离线weixun8912
 

只看楼主 倒序阅读 楼主  发表于: 2014-01-24

#include "getip.h"

getIP::getIP(QWidget *parent, Qt::WFlags flags)
    : QWidget(parent, flags)
{
    ui.setupUi(this);
    QHostInfo::lookupHost("www.baidu.com",
        this, SLOT(lookedUp(const QHostInfo&)));

}

getIP::~getIP()
{

}


void getIP::lookedUp(const QHostInfo &host)
{
    if (host.error() != QHostInfo::NoError) {
        qDebug() << "Lookup failed:" << host.errorString();
        return;
    }

    foreach (const QHostAddress &address, host.addresses())
        qDebug() << "Found address:" << address.toString();


    /*QList<QHostAddress> addressList =host.addresses();
    qDebug()<<"the host address ip count is "<<addressList.size();

    for (int index=0;index<addressList.size();++index)
    {
        qDebug<<"The"<<index<<"ip is"<<addressList.at(index).toString();
    }*/



}


我想用这个函数返回局域网里同名计算机的IP地址?明明有两台不同Ip的同名计算机,可函数只返回了一个IP,想问问大家这是为什么?
快速回复
限100 字节
 
上一个 下一个