增加: 广播模块
This commit is contained in:
parent
f2fa0746a2
commit
ffa89d0bef
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -4,4 +4,5 @@ release/*
|
||||||
HxUtils.pro.*
|
HxUtils.pro.*
|
||||||
Makefile*
|
Makefile*
|
||||||
*.Debug
|
*.Debug
|
||||||
*.Release
|
*.Release
|
||||||
|
*.TMP
|
17
HxBroadcast.cpp
Normal file
17
HxBroadcast.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include "HxBroadcast.h"
|
||||||
|
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
|
int HxBroadcast::port = 0;
|
||||||
|
QUdpSocket *HxBroadcast::socket = nullptr;
|
||||||
|
|
||||||
|
void HxBroadcast::initialization(int port)
|
||||||
|
{
|
||||||
|
HxBroadcast::port = port;
|
||||||
|
HxBroadcast::socket = new QUdpSocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HxBroadcast::publish(QString message)
|
||||||
|
{
|
||||||
|
socket->writeDatagram(message.toUtf8(), QHostAddress::Broadcast, port);
|
||||||
|
}
|
29
HxBroadcast.h
Normal file
29
HxBroadcast.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef HXBROADCAST_H
|
||||||
|
#define HXBROADCAST_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUdpSocket>
|
||||||
|
|
||||||
|
class HxBroadcast
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief 初始化
|
||||||
|
*
|
||||||
|
* @param port 广播端口
|
||||||
|
*/
|
||||||
|
static void initialization(int port);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 发布消息
|
||||||
|
*
|
||||||
|
* @param message 消息
|
||||||
|
*/
|
||||||
|
static void publish(QString message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static int port;
|
||||||
|
static QUdpSocket *socket;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // HXBROADCAST_H
|
|
@ -29,6 +29,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
HxBroadcast.cpp \
|
||||||
HxDisk.cpp \
|
HxDisk.cpp \
|
||||||
HxLog.cpp \
|
HxLog.cpp \
|
||||||
HxProcess.cpp \
|
HxProcess.cpp \
|
||||||
|
@ -40,6 +41,7 @@ SOURCES += \
|
||||||
HxTrace.cpp
|
HxTrace.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
HxBroadcast.h \
|
||||||
HxDisk.h \
|
HxDisk.h \
|
||||||
HxLog.h \
|
HxLog.h \
|
||||||
HxProcess.h \
|
HxProcess.h \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user