Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mahuifa
QMDemo
提交
75c70166
Q
QMDemo
项目概览
mahuifa
/
QMDemo
通知
1
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
QMDemo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
75c70166
编写于
4月 21, 2022
作者:
mahuifa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新功能:网络接口信息模块功能开发
1、修改SimpleTcpServer中client的释放方法; 2、增加获取所有网络接口名称功能。
上级
dd2b4de4
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
159 addition
and
5 deletion
+159
-5
QMNetwork/NetInterface/NetInterface.pri
QMNetwork/NetInterface/NetInterface.pri
+18
-0
QMNetwork/NetInterface/netproperty.cpp
QMNetwork/NetInterface/netproperty.cpp
+30
-0
QMNetwork/NetInterface/netproperty.h
QMNetwork/NetInterface/netproperty.h
+26
-0
QMNetwork/NetInterface/netproperty.ui
QMNetwork/NetInterface/netproperty.ui
+47
-0
QMNetwork/SimpleNetWidget/simpletcpserver.cpp
QMNetwork/SimpleNetWidget/simpletcpserver.cpp
+2
-3
QMNetwork/widget.cpp
QMNetwork/widget.cpp
+18
-0
QMNetwork/widget.h
QMNetwork/widget.h
+4
-1
QMNetwork/widget.ui
QMNetwork/widget.ui
+14
-1
未找到文件。
QMNetwork/NetInterface/NetInterface.pri
浏览文件 @
75c70166
#---------------------------------------------------------
# 功能: 获取设备网络信息
# 编译器:
#
# @开发者 mhf
# @邮箱 1603291350@qq.com
# @时间 2022/04/21
# @备注
#---------------------------------------------------------
FORMS += \
$$PWD/netproperty.ui
HEADERS += \
$$PWD/netproperty.h
SOURCES += \
$$PWD/netproperty.cpp
QMNetwork/NetInterface/netproperty.cpp
0 → 100644
浏览文件 @
75c70166
#
include
"netproperty.h"
#include "ui_netproperty.h"
#include <qnetworkinterface.h>
NetProperty
::
NetProperty
(
QWidget
*
parent
)
:
QWidget
(
parent
),
ui
(
new
Ui
::
NetProperty
)
{
ui
->
setupUi
(
this
);
init
();
}
NetProperty
::~
NetProperty
()
{
delete
ui
;
}
void
NetProperty
::
init
()
{
// 获取所有网络接口
const
QList
<
QNetworkInterface
>
interfaces
=
QNetworkInterface
::
allInterfaces
();
ui
->
com_Interface
->
clear
();
for
(
auto
interface
:
interfaces
)
{
qDebug
()
<<
interface
.
humanReadableName
()
<<
interface
.
name
()
<<
interface
.
type
();
ui
->
com_Interface
->
addItem
(
interface
.
humanReadableName
());
// 显示所有网络接口名称
}
}
QMNetwork/NetInterface/netproperty.h
0 → 100644
浏览文件 @
75c70166
#
ifndef
NETPROPERTY_H
#define NETPROPERTY_H
#include <QWidget>
namespace
Ui
{
class
NetProperty
;
}
class
NetProperty
:
public
QWidget
{
Q_OBJECT
public:
explicit
NetProperty
(
QWidget
*
parent
=
nullptr
);
~
NetProperty
();
private:
void
init
();
private:
Ui
::
NetProperty
*
ui
;
};
#endif // NETPROPERTY_H
QMNetwork/NetInterface/netproperty.ui
0 → 100644
浏览文件 @
75c70166
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
NetProperty
</class>
<widget
class=
"QWidget"
name=
"NetProperty"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
400
</width>
<height>
300
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Form
</string>
</property>
<widget
class=
"QWidget"
name=
""
>
<property
name=
"geometry"
>
<rect>
<x>
10
</x>
<y>
30
</y>
<width>
341
</width>
<height>
22
</height>
</rect>
</property>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout"
>
<item>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Fixed"
vsizetype=
"Preferred"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
网络接口:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QComboBox"
name=
"com_Interface"
/>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
QMNetwork/SimpleNetWidget/simpletcpserver.cpp
浏览文件 @
75c70166
...
...
@@ -73,9 +73,8 @@ void SimpleTcpServer::on_disconnected()
disconnect
(
m_client
,
&
QTcpSocket
::
disconnected
,
this
,
&
SimpleTcpServer
::
on_disconnected
);
// 断开绑定的信号槽
disconnect
(
m_client
,
&
QTcpSocket
::
readyRead
,
this
,
&
SimpleTcpServer
::
on_readyRead
);
//delete m_client; // 这里不能用delete,否则在vs里会报错 0x00007FFBF870A1CE (Qt5Networkd.dll)处(位于 QMNetwork.exe 中)引发的异常: 0xC0000005: 读取位置 0xFFFFFFFFFFFFFFFF 时发生访问冲突。
QTcpSocket
*
tcpSocket
=
m_client
;
m_client
=
nullptr
;
// 先将m_client置空,因为deleteLater不会置空
tcpSocket
->
deleteLater
();
// 移除已经断开连接的Client(注意这里不能使用delete,否则在vs中会报错),但这种方式不会置为 空
m_client
->
deleteLater
();
// 移除已经断开连接的Client(注意这里不能使用delete,否则在vs中会报错),但这种方式不会置为 空
m_client
=
nullptr
;
}
/**
...
...
QMNetwork/widget.cpp
浏览文件 @
75c70166
...
...
@@ -28,6 +28,12 @@ Widget::~Widget()
*/
void
Widget
::
on_pushButton_clicked
()
{
if
(
m_netProperty
)
{
delete
m_netProperty
;
m_netProperty
=
nullptr
;
}
// 简易版
while
(
m_simpleTcpClients
.
count
())
{
...
...
@@ -144,3 +150,15 @@ void Widget::on_but_simpleUdpGroup_clicked()
m_simpleUdpGroups
.
last
()
->
show
();
}
/**
* @brief 打开网络属性窗口
*/
void
Widget
::
on_but_property_clicked
()
{
if
(
!
m_netProperty
)
{
m_netProperty
=
new
NetProperty
();
}
m_netProperty
->
show
();
}
QMNetwork/widget.h
浏览文件 @
75c70166
...
...
@@ -11,7 +11,7 @@
#include "simpleudpsocket1.h"
#include "simpleudpsocket2.h"
#include "simpleudpgroup.h"
#include "netproperty.h"
QT_BEGIN_NAMESPACE
namespace
Ui
{
class
Widget
;
}
...
...
@@ -44,8 +44,11 @@ private slots:
void
on_but_simpleUdpGroup_clicked
();
void
on_but_property_clicked
();
private:
Ui
::
Widget
*
ui
;
NetProperty
*
m_netProperty
=
nullptr
;
// 网络属性窗口
/******************简易版网络通信Demo********************/
QList
<
SimpleTcpClient
*>
m_simpleTcpClients
;
// 可打开任意多个TCP客户端
QList
<
SimpleTcpServer
*>
m_simpleTcpServers
;
// 可打开任意多个TCP服务端
...
...
QMNetwork/widget.ui
浏览文件 @
75c70166
...
...
@@ -129,13 +129,26 @@
<string>
HTTP
</string>
</property>
</widget>
<widget
class=
"QPushButton"
name=
"but_property"
>
<property
name=
"geometry"
>
<rect>
<x>
290
</x>
<y>
80
</y>
<width>
75
</width>
<height>
23
</height>
</rect>
</property>
<property
name=
"text"
>
<string>
网络属性
</string>
</property>
</widget>
</widget>
<widget
class=
"QGroupBox"
name=
"groupBox_2"
>
<property
name=
"geometry"
>
<rect>
<x>
20
</x>
<y>
160
</y>
<width>
4
6
1
</width>
<width>
4
7
1
</width>
<height>
111
</height>
</rect>
</property>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录