feat: UDP 创建界面好了,和部分槽函数

This commit is contained in:
touwoyimuli 2019-11-30 00:00:53 +08:00
parent 098d039040
commit 50d0530a55
15 changed files with 386 additions and 6 deletions

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved.
*
* Author: touwoyimuli <touwoyimuli@gmai.com>
*
* github: https://github.com/touwoyimuli
* blogs: https://touwoyimuli.github.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://touwoyimuli.github.io/>.
*/
#include "ExTrans.h"
#include "ui_ExTrans.h"
ExTrans::ExTrans(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ExTrans)
{
ui->setupUi(this);
setWindowTitle("Tcp通信unicast(单播) + broadcast(广播)的使用");
}
ExTrans::~ExTrans()
{
delete ui;
}
void ExTrans::on_actBind_triggered()
{
}
void ExTrans::on_actDisbind_triggered()
{
}
void ExTrans::on_actClean_triggered()
{
}
void ExTrans::on_actQuit_triggered()
{
close();
}

49
QtUdpEx/ExTrans/ExTrans.h Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved.
*
* Author: touwoyimuli <touwoyimuli@gmai.com>
*
* github: https://github.com/touwoyimuli
* blogs: https://touwoyimuli.github.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://touwoyimuli.github.io/>.
*/
#ifndef EXTRANS_H
#define EXTRANS_H
#include <QMainWindow>
namespace Ui {
class ExTrans;
}
class ExTrans : public QMainWindow
{
Q_OBJECT
public:
explicit ExTrans(QWidget *parent = nullptr);
~ExTrans();
private slots:
void on_actBind_triggered();
void on_actDisbind_triggered();
void on_actClean_triggered();
void on_actQuit_triggered();
private:
Ui::ExTrans *ui;
};
#endif // EXTRANS_H

View File

@ -0,0 +1,55 @@
#-------------------------------------------------
#
# Project created by QtCreator 2019-11-29T22:57:12
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ExTrans
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
ExTrans.cpp
HEADERS += \
ExTrans.h
FORMS += \
ExTrans.ui
macx {
ICON = images/icon.icns
}
unix:!macx{
# linux only
}
win32 {
RC_ICONS = images/icon.ico
}
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
resources.qrc

186
QtUdpEx/ExTrans/ExTrans.ui Normal file
View File

@ -0,0 +1,186 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExTrans</class>
<widget class="QMainWindow" name="ExTrans">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>671</width>
<height>448</height>
</rect>
</property>
<property name="windowTitle">
<string>ExTrans</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>绑定端口:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<property name="maximum">
<number>65000</number>
</property>
<property name="value">
<number>8888</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>目标地址:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>目标端口:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_2">
<property name="maximum">
<number>65000</number>
</property>
<property name="value">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>单播发送</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>广播发送</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>671</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actBind"/>
<addaction name="actDisbind"/>
<addaction name="separator"/>
<addaction name="actClean"/>
<addaction name="separator"/>
<addaction name="actQuit"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actBind">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/Image6.png</normaloff>:/images/Image6.png</iconset>
</property>
<property name="text">
<string>绑定</string>
</property>
<property name="toolTip">
<string>绑定端口</string>
</property>
</action>
<action name="actDisbind">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/Image3.png</normaloff>:/images/Image3.png</iconset>
</property>
<property name="text">
<string>解绑定</string>
</property>
<property name="toolTip">
<string>解除绑定</string>
</property>
</action>
<action name="actClean">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/Image1.png</normaloff>:/images/Image1.png</iconset>
</property>
<property name="text">
<string>清空</string>
</property>
<property name="toolTip">
<string>清空文本</string>
</property>
</action>
<action name="actQuit">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/Image2.jpg</normaloff>:/images/Image2.jpg</iconset>
</property>
<property name="text">
<string>退出</string>
</property>
<property name="toolTip">
<string>退出程序</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

BIN
QtUdpEx/ExTrans/images/icon.icns Executable file

Binary file not shown.

BIN
QtUdpEx/ExTrans/images/icon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

11
QtUdpEx/ExTrans/main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "ExTrans.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ExTrans w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,10 @@
<RCC>
<qresource prefix="/">
<file>images/Image1.png</file>
<file>images/Image2.jpg</file>
<file>images/Image3.png</file>
<file>images/Image4.png</file>
<file>images/Image5.png</file>
<file>images/Image6.png</file>
</qresource>
</RCC>

View File

@ -34,11 +34,12 @@
## 第一部分:预备知识
- `windows`环境下安装`Qt Creator`作为`c++`的**IDE**开发工具,学习和使用**qt** (推荐)
- `windows10`环境下安装`Qt Creator5.9.8`作为`c++`的**IDE**开发工具,学习和使用**qt** (最佳推荐)
- `MacOS10.14.6`环境下安装`QtCreator5.9.8`作为`c++`的**IDE**开发工具,学习和使用**qt**(推荐)
- [Qt Creator 安装SDK在MSVC编译模式下使用CDB调试器](https://blog.csdn.net/qq_33154343/article/details/98779698)
- `windows`环境下安装`Qt Creator` + `Visual Studio 2015`作为`c++`的`IDE`开发工具,学习和使用**qt** (备选)
- [`windows`环境下安装`Qt Creator 5.9` + `Visual Studio 2017专业版`](https://blog.csdn.net/qq_33154343/article/details/78587699) 参考此文 (备选)
- `Qt Creator` **IDE**的界面组成和使用讲解
- `Qt Creator` **IDE**的界面基本组成和入门使用讲解
- 编写一个**qt**的第一个项目: `Hello World`的项目
<br>
@ -64,13 +65,25 @@
- 目录树组件`QTreeWidget`和停靠区域组件`QDockWidget`的用法【QtQTreeWidgetEx】
- 【QtQTableWidgetEx】
- 【QtQFileSystemModelEx】
- 【QtQDialogEx】
- 【QtQStandardItemModelEx】
- 【QtQStringListModelEx】
- 自定义风格控件样式【QtCustomDialogEx】
- 多文档界面MDI(Multi-document Interface)的实现QMdiArea使用【QtMDIEx】
## 第四部分:网络编程
- 主机信息查询QHostInfo和QNetworkInterface查询IP等【QtQHostInfoEx】
- TCP通信之QTcpServer和QTcpSocket服务器和客户端通讯【QtTcpEx】
<br>
## 第四部分自定义风格样式QStyle
## 扩展部分自定义风格样式QStyle
- 自定义`QStyle`界面所有控件的风格,换肤效果的教程,自定义继承`QCommonStyle`的风格类【QtCustomStyleEx】
- 预备知识:`QStyle`、`QCommonStyle`d等讲解
- 预备知识:`QStyle`、`QCommonStyle`等讲解
- [更换`Qt`应用程序的界面`UI`,实现换肤,改用自带其他默认`QStyle`风格样式](https://mp.csdn.net/mdeditor/100148539#)
- [`QStyle`自定义重绘滑动条`QSlider`控件](https://blog.csdn.net/qq_33154343/article/details/100545769)
- [`QStyle`自定义重绘`QRubberBand`控件](https://blog.csdn.net/qq_33154343/article/details/100588428)
@ -109,9 +122,9 @@
## 同步github.io博客
- github.io的同步总目录[WiKi](https://github.com/touwoyimuli/QtExamples/wiki/Qt%E6%8E%A8%E5%80%92%E9%87%8D%E5%AD%A6%E7%B3%BB%E5%88%97--%E6%80%BB%E7%9B%AE%E5%BD%95%E3%80%90github.io%E3%80%91)
- `github.io`的同步总目录:[WiKi](https://github.com/touwoyimuli/QtExamples/wiki/Qt%E6%8E%A8%E5%80%92%E9%87%8D%E5%AD%A6%E7%B3%BB%E5%88%97--%E6%80%BB%E7%9B%AE%E5%BD%95%E3%80%90github.io%E3%80%91)
- Qt Creator使用小技巧[WiKi](https://github.com/touwoyimuli/QtExamples/wiki/Qt%E4%BD%BF%E7%94%A8%E7%9A%84%E4%B8%80%E4%B8%8B%E5%B0%8F%E6%8A%80%E5%B7%A7)
- `Qt Creator`使用小技巧:[WiKi](https://github.com/touwoyimuli/QtExamples/wiki/Qt%E4%BD%BF%E7%94%A8%E7%9A%84%E4%B8%80%E4%B8%8B%E5%B0%8F%E6%8A%80%E5%B7%A7)
<br>