使用qt的hostInfo类,查看本机的IP和设备
创建NetWorkInformation类,main.cpp直接生成。
#include "networkinformation.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
NetworkInformation w;
w.show(); return a.exec();
}
头文件声明要写的槽函数,还有布局控件。
#ifndef NETWORKINFORMATION_H
#define NETWORKINFORMATION_H #include <QWidget>
#include <QHostInfo>
#include <QNetworkInterface>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGridLayout>
class NetworkInformation : public QWidget
{
Q_OBJECT public:
NetworkInformation(QWidget *parent = );
~NetworkInformation();
public:
void getHostInformation();
public slots:
void slotDetail();
private:
QLabel *hostLabel;
QLineEdit *LineEditLocalHostname;
QLabel * ipLabel;
QLineEdit * LineEditAddress;
QPushButton* detailBtn;
QGridLayout * mainLayout;
}; #endif // NETWORKINFORMATION_H
最后是.cpp的文件。
在构造函数里写控件的布局,然后实现槽函数。
#include "networkinformation.h"
#include <QMessageBox>
NetworkInformation::NetworkInformation(QWidget *parent)
: QWidget(parent)
{
hostLabel = new QLabel("name:");
LineEditLocalHostname = new QLineEdit;
ipLabel = new QLabel(tr("ip:"));
LineEditAddress = new QLineEdit;
detailBtn = new QPushButton(tr("detail"));
mainLayout =new QGridLayout(this); mainLayout->addWidget(hostLabel,,);
mainLayout->addWidget(LineEditLocalHostname,,);
mainLayout->addWidget(ipLabel,,);
mainLayout->addWidget(LineEditAddress,,);
mainLayout->addWidget(detailBtn,,,,);
getHostInformation();
connect(detailBtn,SIGNAL(clicked()),this,SLOT(slotDetail()));
} NetworkInformation::~NetworkInformation()
{ }
void NetworkInformation::getHostInformation()
{
QString localHostName = QHostInfo::localHostName();
LineEditLocalHostname->setText(localHostName); QHostInfo hostinfo = QHostInfo::fromName(localHostName); foreach (const QHostAddress &address, hostinfo.addresses())
{ if (address.protocol() == QAbstractSocket::IPv4Protocol)
{
LineEditAddress->setText((address.toString()));
}
}
}
void NetworkInformation::slotDetail()
{
QString detail="";
QList<QNetworkInterface>list=QNetworkInterface::allInterfaces();
for(int i=;i<list.count();i++)
{
QNetworkInterface interface = list.at(i);
detail= detail+tr("设备:")+interface.name()+"\n";
detail= detail+tr("硬件地址:")+interface.hardwareAddress()+"\n";
QList<QNetworkAddressEntry>entryList = interface.addressEntries();
for(int j =;j<entryList.count();j++)
{
/QNetworkAddressEntry entry = entryList.at(i);
detail = detail + "\t" +tr("IP 地址:")+entry.ip().toString()+"\n";
detail = detail + "\t" + tr("子网掩码:")+entry.netmask().toString()+"\n";
detail = detail + "\t" +tr("广播地址:") +entry.broadcast().toString()+"\n";
}
}
QMessageBox::information(this,tr("Detail"),detail);
}
使用qt的hostInfo类,查看本机的IP和设备的更多相关文章
- 查看本机的IP地址方法:
查看本机的IP地址方法:对于XP系统:方法一:如果右下角系统托盘区有本地连接的小电脑,双击小电脑→支持,就可以看到本机IP地址.无线连接也是一样.方法二:开始→运行cmd /k ipconfig,IP ...
- (转)linux获取/查看本机出口ip
获取/查看本机出口ip curl http://members.3322.org/dyndns/getip 1 curl ifconfig.me 2 #或者 3 curl http://member ...
- 查看本机的ip地址
ifconfig可以查看本机的ip地址:inet addr:10.108.104.185
- 查看本机的ip
1.Windows 1.1.查看ip地址 ipconfig 1.2.查看MAC地址 ipconfig /all 2.Linux 2.1.查看ip地址 ifconfig 2.2.查看MAC地址 ip l ...
- Ubuntu 查看本机的ip
打开终端中执行:ifconfig -a命令即可,如下图所示白色背景信息即是. 说明: enp0s3 表示第一块网卡, 其中 HWaddr 表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址 ...
- CentOS查看本机公网IP命令
icanhazip.com 使你在任何地方知道你的公网IP地址 icanhazip.com是一个网址,你在浏览器中输入这个网址,你就能得到你的公网IP地址了. 我在Linux下一般使用curl ica ...
- 转载:CentOS查看本机公网IP命令
icanhazip.com 使你在任何地方知道你的公网IP地址 icanhazip.com是一个网址,你在浏览器中输入这个网址,你就能得到你的公网IP地址了. 我在Linux下一般使用curl ica ...
- Mac 命令行查看自己的公网IP
Mac 查看本机公网IP 命令 curl ifconfig.me 如果想更好看一点 curl ipinfo.io/json 还可以用wget wget http://ipecho.net/plain ...
- Window、Linux查看本机外网ip
前言 我们上网用的IP并不一定是本机网卡的IP地址,由于公网IP地址稀少,国内绝大多数电脑上网,一般都是通过拨号或者端口映射.多个内网地址映射到一个公网地址来实现上网的. 目录 1.查看本机网卡ip ...
随机推荐
- 利用URL Scheme打开APP并传递数据
https://blog.csdn.net/u013517637/article/details/55251421 利用外部链接打开APP并传递一些附带信息是现在很多APP都有的功能,我在这把这部分的 ...
- 生产html测试报告
批量执行完用例后,生成的测试报告是文本形式的,不够直观,为了更好的展示测试报告,最好是生成 HTML 格式的.unittest 里面是不能生成 html 格式报告的,需要导入一个第三方的模块:HTML ...
- unittest简介
unittest是python里面的单元测试框架 1 unittest 简介 1).先导入 unittest2).用 help 函数查看源码解析3).查看描述:Python unit testing ...
- 关于mouseleave事件触发的bug问题
在做下拉树搜索功能的时候,下方内容框需要一个鼠标移出时就隐藏的功能,于是使用mouseleave的方法, 但是出现了一个问题就是在点击树展开个隐藏的时候,也触发了leave事件,将下方的树进行隐藏,出 ...
- java获取当前秒数输出
Date的getSeconds()已经过时了.不建议用.所以用了下面方法 Calendar c = Calendar.getInstance(); while(true) { c ...
- git 学习之基础知识
在前面的一个帖子中我们知道了不同的版本控制系统的不同,在这个帖子中我们会大致的了解到它们是管理各个版本的,这对我们学习 git 是很有帮助的. 对于集中式的版本控制系统来说每次的更新主要记录内容的具体 ...
- PHP返回404状态码,由服务器处理
1. 通过header()方法来实现, 最简单的方法,而且对php的版本没什么限制 <?php header('HTTP/1.1 404 Not Found'); ...
- [转]oracle update set select from 关联更新
本文转自:http://blog.csdn.net/disiwei1012/article/details/52589181 http://www.blogjava.net/Jhonney/archi ...
- Expression Blend实例中文教程(10) - 缓冲动画快速入门Easing
随着Rich Internet application(RIA)应用技术的发展,各个公司越来越注重于项目的用户体验性,在保证其功能完善,运行稳定的基础上,绚丽的UI和人性化的操作设计会给用户带来舒适的 ...
- deblurGAN
-- main.py -- util.py -- data_loader.py -- mode.py -- DeblurGAN.py -- vgg19.py -- layer.py -- vgg19. ...