增加: 广播模块

This commit is contained in:
hehaoyang 2024-01-11 19:57:40 +08:00
parent f2fa0746a2
commit ffa89d0bef
4 changed files with 50 additions and 1 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ release/*
HxUtils.pro.* HxUtils.pro.*
Makefile* Makefile*
*.Debug *.Debug
*.Release *.Release
*.TMP

17
HxBroadcast.cpp Normal file
View 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
View 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

View File

@ -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 \