首页 > 代码库 > QT 网络编程
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);}
QT 网络编程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。