• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
对时间的反省
博客园    首页    新随笔    联系   管理    订阅  订阅

QT 网络编程

#include "networkinformation.h"
#include "ui_networkinformation.h"

networkinformation::networkinformation(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::networkinformation)
{
    ui->setupUi(this);
    getHostInformation ();
    connect (ui->detailBtn,SIGNAL(clicked()),this,SLOT(slotDetail()));
}

networkinformation::~networkinformation()
{
    delete ui;
}

void networkinformation::getHostInformation ()
{
    QString localHostName = QHostInfo::localHostName ();
    ui->lineEditLocalHostName->setText(localHostName);

    QHostInfo hostInfo = QHostInfo::fromName (localHostName);
    QList<QHostAddress> listAddress = hostInfo.addresses ();
    if(!listAddress.isEmpty ())
    {
        ui->lineEditAddress->setText(listAddress.first().toString());
    }
}


void networkinformation::slotDetail ()
{
    QString detail="";
    QList<QNetworkInterface> list=QNetworkInterface::allInterfaces ();
    for(int i=0;i<list.count();i++)
    {
        QNetworkInterface interface=list.at(i);
        detail=detail+"equipment :"+interface.name()+"\n";
        detail=detail+"hardware address :"+interface.hardwareAddress ()+"\n";
        QList<QNetworkAddressEntry> entryList=interface.addressEntries ();
        for(int j=0;j<entryList.count ();j++)
        {
            QNetworkAddressEntry entry=entryList.at(j);
            detail=detail+"\t"+"IP Address :"+entry.ip ().toString ()+"\n";
            detail=detail+"\t"+"subnet mask :"+entry.netmask().toString ()+"\n";
            detail=detail+"\t"+"broadcast address :"+entry.broadcast ().toString ()+"\n";
        }
    }
    QMessageBox::information (this,"detail",detail);
}

  

posted @ 2014-10-07 23:53  zhaoying  阅读(307)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3