我的主页

快递查询 :http://m.kuaidi100.com     爱快递查询 :http://www.aikuaidi.cn/              

http://www.qtcn.org/bbs/u/168050  [收藏] [复制]

w642833823

  • 7

    关注

  • 20

    粉丝

  • 17

    访客

  • 等级:新手上路
  • 总积分:38
  • 保密,2011-12-07

最后登录:2019-09-23

更多资料

日志

获取系统IP的三种方式收藏

2019-09-11 05:15
/*

#include <QtNetwork>
#include <QHostInfo>
//方法一
QString localHostName = QHostInfo::localHostName();
//qDebug() <<"localHostName: "<<localHostName;
QHostInfo info = QHostInfo::fromName(localHostName);
//qDebug() <<"IP Address: "<<info.addresses();    
QList<QHostAddress> address=info.addresses();  
*/ //获取主机的IP地址
//QString Ip=QString(address.first().toString());
//方法二
/*QString detail="";
QList<QNetworkInterface> list=QNetworkInterface::allInterfaces();//提供主机ip地址和网络接口
for(int i=1;i<list.count();i++){
    QNetworkInterface interface=list.at(i);
    detail=detail+tr("设备")+interface.name()+"\n";
    detail=detail+tr("硬件地址")+interface.hardwareAddress()+"\n";
    QList<QNetworkAddressEntry> entryList=interface.addressEntries();//提供子网掩码和ip地址以及广播地址
    for(int j=1;j<entryList.count();j++) {
        QNetworkAddressEntry entry=entryList.at(j);
        detail+=" "+tr("ip")+entry.ip().toString()+"\n";
        detail+=" "+tr("子网掩码")+entry.netmask().toString()+"\n";
        detail+=" "+tr("广播地址")+entry.broadcast().toString()+"\n";
    }
}*/
//方法三
QString localHostName = QHostInfo::localHostName();
QHostInfo info = QHostInfo::fromName(localHostName);
QHostAddress address;
foreach(address,info.addresses()){
        if(address.protocol()==QAbstractSocket::IPv4Protocol){
            qDebug()<<address.toString();
        }
    }


分类:手机端开发版|回复:0|浏览:61|全站可见|转载
 

Powered by phpwind v8.7 Certificate Copyright Time now is:09-23 08:29
©2005-2016 QTCN开发网 版权所有 Gzip disabled