chore: update macro definition

This commit is contained in:
x-tools-author 2024-03-25 16:00:57 +08:00
parent 8e1fe1a5ae
commit 556efef0ea
7 changed files with 15 additions and 19 deletions

View File

@ -13,20 +13,20 @@
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#define SAK_SIG_SOCKETERROROCCURRED &QAbstractSocket::errorOccurred
#define X_TOOLS_ABSTRACT_SOCKET_ERROR_OCCURRED &QAbstractSocket::errorOccurred
#else
#define SAK_SIG_SOCKETERROROCCURRED \
#define X_TOOLS_ABSTRACT_SOCKET_ERROR_OCCURRED \
static_cast<void (QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error)
#endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#define SAK_SIG_WEBSOCKETERROROCCURRED &QWebSocket::errorOccurred
#define X_TOOLS_WEB_SOCKET_ERROR_OCCURRED &QWebSocket::errorOccurred
#else
#define SAK_SIG_WEBSOCKETERROROCCURRED \
#define X_TOOLS_WEB_SOCKET_ERROR_OCCURRED \
static_cast<void (QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error)
#endif
static qint64 sakBirthTimeOfFile(const QFileInfo &info)
static qint64 xToolsBirthTimeOfFile(const QFileInfo &info)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
return info.birthTime().toMSecsSinceEpoch();

View File

@ -39,7 +39,7 @@ bool xToolsTcpClientTool::initialize(QString& errStr)
qInfo() << "Client address and port: " + m_bindingIpPort;
emit bindingIpPortChanged();
connect(mTcpSocket, SAK_SIG_SOCKETERROROCCURRED, mTcpSocket, [=]() {
connect(mTcpSocket, X_TOOLS_ABSTRACT_SOCKET_ERROR_OCCURRED, mTcpSocket, [=]() {
QString info = "Error occurred: " + mTcpSocket->errorString();
qInfo() << info;
emit errorOccurred(mTcpSocket->errorString());

View File

@ -60,7 +60,7 @@ bool xToolsTcpServerTool::initialize(QString &errStr)
emit clientsChanged();
});
connect(client, SAK_SIG_SOCKETERROROCCURRED, client, [=]() {
connect(client, X_TOOLS_ABSTRACT_SOCKET_ERROR_OCCURRED, client, [=]() {
this->m_tcpSocketListMutex.lock();
this->m_tcpSocketList.removeOne(client);
this->m_tcpSocketListMutex.unlock();

View File

@ -40,7 +40,7 @@ bool xToolsUdpClientTool::initialize(QString &errStr)
emit bindingIpPortChanged();
connect(m_udpSocket, &QUdpSocket::readyRead, m_udpSocket, [=]() { readBytes(); });
connect(m_udpSocket, SAK_SIG_SOCKETERROROCCURRED, this, [=]() {
connect(m_udpSocket, X_TOOLS_ABSTRACT_SOCKET_ERROR_OCCURRED, this, [=]() {
emit errorOccurred(m_udpSocket->errorString());
});

View File

@ -38,7 +38,7 @@ bool xToolsUdpServerTool::initialize(QString &errStr)
emit bindingIpPortChanged();
connect(m_udpSocket, &QUdpSocket::readyRead, m_udpSocket, [=]() { readBytes(); });
connect(m_udpSocket, SAK_SIG_SOCKETERROROCCURRED, this, [=]() {
connect(m_udpSocket, X_TOOLS_ABSTRACT_SOCKET_ERROR_OCCURRED, this, [=]() {
emit errorOccurred(m_udpSocket->errorString());
});

View File

@ -55,7 +55,7 @@ bool xToolsWebSocketClientTool::initialize(QString &errStr)
emit bytesRead(message.toUtf8(), this->m_peerInfo);
});
connect(m_webSocket, SAK_SIG_WEBSOCKETERROROCCURRED, m_webSocket, [=]() {
connect(m_webSocket, X_TOOLS_WEB_SOCKET_ERROR_OCCURRED, m_webSocket, [=]() {
QString errStr = m_webSocket->errorString();
emit errorOccurred(errStr);
});

View File

@ -10,10 +10,9 @@
#include <QWebSocket>
#include "xToolsCompatibility.h"
#include "xToolsInterface.h"
#define WS_ERR_SIGNAL void (QWebSocket::*)(QAbstractSocket::SocketError)
xToolsWebSocketServerTool::xToolsWebSocketServerTool(QObject *parent)
: xToolsSocketServerTool{parent}
{}
@ -75,16 +74,13 @@ bool xToolsWebSocketServerTool::initialize(QString &errStr)
connect(client, &QWebSocket::disconnected, client, [=]() {
this->mWebSocketList.removeOne(client);
this->m_clients.removeOne(ipPort);
qInfo() << QString("Connection(%1) has been disconnected: %2")
.arg(mBindingIpPort, client->errorString());
qInfo() << qPrintable(QString("Connection(%1) has been disconnected: %2")
.arg(mBindingIpPort, client->errorString()));
emit clientsChanged();
});
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(client,
static_cast<WS_ERR_SIGNAL>(&QWebSocket::errorOccurred),
#else
connect(client, static_cast<WS_ERR_SIGNAL>(&QWebSocket::error),
#endif
X_TOOLS_WEB_SOCKET_ERROR_OCCURRED,
client,
[=](QAbstractSocket::SocketError err) {
Q_UNUSED(err);