我的主页

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

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

w642833823

  • 7

    关注

  • 20

    粉丝

  • 20

    访客

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

最后登录:2019-10-18

更多资料

日志

在手机上处理获取当前移动网络的IP地址

2019-09-12 21:55
  #include <QtNetwork>
//#include <QHostInfo>
//#include <QHostAddress>
    
/*
*获取本机Ip地址
*/

    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    QString ipAddress;
    // use the first non-localhost IPv4 address
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
            ipAddressesList.at(i).toIPv4Address()) {
            ipAddress = ipAddressesList.at(i).toString();
            break;
        }
    }
    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
    qDebug()<<"IP为:"<<ipAddress;




    text_Edit = new QTextEdit;
    text_Edit->setText("本机IP:"+ipAddress);
分类:默认分类|回复:0|浏览:57|全站可见|转载
 

Powered by phpwind v8.7 Certificate Copyright Time now is:10-19 00:38
©2005-2016 QTCN开发网 版权所有 Gzip disabled