zoukankan      html  css  js  c++  java
  • Qt

    目的:

      获取本机的主机名、IP地址、硬件地址等网络信息。

    工具:

      使用Qt提供的网络模块QtNetwork(pro文件里面加network);

      使用Qt提供的类QHostInfo、QNetworkInterface、QNetworkAddressEntry。

    代码:

      获取本机主机名和IP地址

    void NetworkInformation::getHostInformation() {  
        //获取本机主机名  
        QString localHostName = QHostInfo::localHostName();  
        LineEditLocalHostName->setText(localHostName);  
      
        //通过本机主机名获取IP地址  
        QHostInfo hostInfo = QHostInfo::fromName(localHostName);  
        QList<QHostAddress> listAddress = hostInfo.addresses();  
        if(!listAddress.isEmpty()) {  
            LineEditAddress->setText(listAddress.first().toString());  
        }  
    }  
    

      获取本机更加详细的信息

    void NetworkInformation::slotDetail() {
        QString detail = "";
    
        //获取主机IP地址和网络接口列表
        QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
        for(int i = 0; i < list.count(); i++) {
            QNetworkInterface interface = list.at(i);
    
            //获取网络接口名称
            detail = detail + tr("设备:") + interface.name() + "
    ";
            //获取网络接口的硬件地址
            detail = detail + tr("硬件地址:") + interface.hardwareAddress() + "
    ";
    
            //获取网络接口对应的IP地址(IPv4和IPv6)、子网掩码、广播地址
            QList<QNetworkAddressEntry> entryList = interface.addressEntries();
            for(int j = 0; j < entryList.count(); j++) {
                QNetworkAddressEntry entry = entryList.at(j);
                detail = detail + "	" + tr("IP 地址:") + entry.ip().toString() + "
    ";
                detail = detail + "	" + tr("子网掩码:") + entry.netmask().toString() + "
    ";
                detail = detail + "	" + tr("广播地址:") + entry.broadcast().toString() + "
    ";
            } 
        }
        QMessageBox::information(this, tr("Detail"), detail);
    }
    

      

    博客园文作者:Citrusliu 博文地址:https://www.cnblogs.com/citrus
  • 相关阅读:
    多表查询
    合并查询与连接查询区别
    union 合并查询语法
    外连接查询left join on 左连接 right join on 右连接
    inner join on 三表查询四表查询5表查询不管多少表都可以
    INEER JOIN..ON两表查询例子
    sql server 三表查询
    两表查询语句
    内连接查询
    转:Exchange Server 2013 一步步安装图解
  • 原文地址:https://www.cnblogs.com/citrus/p/11811668.html
Copyright © 2011-2022 走看看