码迷,mamicode.com
首页 > 其他好文 > 详细

QT 网络编程

时间:2014-10-08 02:00:24      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   ar   for   div   c   on   log   

#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);
}

  

QT 网络编程

标签:blog   io   os   ar   for   div   c   on   log   

原文地址:http://www.cnblogs.com/zhying13/p/4010312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!