xp-sp3: change grammer to support Qt5.6.3 for xp with sp3 system.

This commit is contained in:
2025-06-25 10:54:04 +08:00
parent 1f9275ed72
commit 60f5cb62b1
26 changed files with 250 additions and 246 deletions

View File

@@ -18,6 +18,11 @@ ClientCore::~ClientCore()
{
}
bool ClientCore::SendFrame(QSharedPointer<FrameBuffer> frame)
{
return Send(frame);
}
void ClientCore::DoConnect(const QString& ip, quint16 port)
{
// qDebug() << "doConnect thread:" << QThread::currentThread();
@@ -31,11 +36,6 @@ void ClientCore::DoConnect(const QString& ip, quint16 port)
bool ClientCore::Connect(const QString& ip, quint16 port)
{
QMutexLocker locker(&conMutex_);
if (!locker.isLocked()) {
qWarning() << QString(tr("%1:%2 already connecting...")).arg(ip).arg(port);
return false;
}
socket_->connectToHost(ip, port);
if (!socket_->waitForConnected(3000)) {
qCritical() << QString(tr("%1:%2 connect failed...")).arg(ip).arg(port);

View File

@@ -9,13 +9,14 @@
#include <Protocol.h>
#include <QDataStream>
#include <QFuture>
#include <QFutureWatcher>
#include <QHostAddress>
#include <QMutex>
#include <QMutexLocker>
#include <QPromise>
#include <QQueue>
#include <QTcpSocket>
#include <QThread>
#include <QtConcurrent/QtConcurrentRun>
#include <array>
class ClientCore : public QObject
@@ -26,6 +27,9 @@ public:
ClientCore(QObject* parent = nullptr);
~ClientCore();
public slots:
bool SendFrame(QSharedPointer<FrameBuffer> frame);
public:
void Instance();
bool Connect(const QString& ip, quint16 port);
@@ -46,30 +50,15 @@ public:
f->type = type;
return f;
}
/*
When calling syncInvoke of ClientCore, the ClientCore should not be in the GUI's event loop thread.
In other words, if a ClientCore instance is created in the GUI thread, it should be moved to another thread;
otherwise, it will cause a deadlock and freeze the interface.
*/
template <typename Callable> static bool syncInvoke(QObject* context, Callable&& func)
static bool syncInvoke(ClientCore* context, QSharedPointer<FrameBuffer> frame)
{
auto promise = QSharedPointer<QPromise<bool>>::create();
QFuture<bool> future = promise->future();
QMetaObject::invokeMethod(
context,
[func = std::forward<Callable>(func), promise]() mutable {
try {
promise->addResult(func());
} catch (...) {
promise->addResult(false);
}
promise->finish();
},
Qt::QueuedConnection);
future.waitForFinished();
return future.result();
bool result = false;
bool success = QMetaObject::invokeMethod(context, "SendFrame", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, result),
Q_ARG(QSharedPointer<FrameBuffer>, frame));
if (!success) {
return false;
}
return result;
}
signals:
@@ -114,7 +103,7 @@ public:
QTcpSocket* socket_{};
QByteArray recvBuffer_;
bool connected_{ false };
bool connected_{false};
LocalFile localFile_;
};

View File

@@ -49,7 +49,7 @@ void FileTrans::ReqSendFile(const TransTask& task)
}
auto frame = clientCore_->GetBuffer(info, FBT_CLI_REQ_SEND, task.remoteId);
if (!ClientCore::syncInvoke(clientCore_, [this, frame]() { return clientCore_->Send(frame); })) {
if (!ClientCore::syncInvoke(clientCore_, frame)) {
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
sendTask_->state = TaskState::STATE_NONE;
sendTask_->file.close();
@@ -79,7 +79,7 @@ void FileTrans::ReqDownFile(const TransTask& task)
return;
}
auto frame = clientCore_->GetBuffer(info, FBT_CLI_REQ_DOWN, task.remoteId);
if (!ClientCore::syncInvoke(clientCore_, [this, frame]() { return clientCore_->Send(frame); })) {
if (!ClientCore::syncInvoke(clientCore_, frame)) {
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
downTask_->state = TaskState::STATE_NONE;
downTask_->file.close();
@@ -154,7 +154,7 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
if (downTask_->state == TaskState::STATE_RUNNING) {
info.msg = QString(tr("busy..."));
auto f = clientCore_->GetBuffer(info, FBT_CLI_CANOT_SEND, frame->fid);
ClientCore::syncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); });
ClientCore::syncInvoke(clientCore_, f);
return;
}
@@ -165,7 +165,7 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
info.msg = QString(tr("open file failed: %1")).arg(newerPath);
qCritical() << info.msg;
auto f = clientCore_->GetBuffer(info, FBT_CLI_CANOT_SEND, frame->fid);
if (!ClientCore::syncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); })) {
if (!ClientCore::syncInvoke(clientCore_, f)) {
qCritical() << QString(tr("open recv file:%2 failed, and reply %2 failed.")).arg(info.msg, f->fid);
downTask_->file.close();
return;
@@ -180,7 +180,7 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
info.msg = QString(tr("open recv file success: %1")).arg(newerPath);
qInfo() << info.msg;
auto f = clientCore_->GetBuffer(info, FBT_CLI_CAN_SEND, frame->fid);
if (!ClientCore::syncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); })) {
if (!ClientCore::syncInvoke(clientCore_, f)) {
qCritical() << QString(tr("open recv file:%2 success, but reply %2 failed.")).arg(info.msg, frame->fid);
downTask_->file.close();
return;
@@ -217,7 +217,7 @@ void FileTrans::fbtReqDown(QSharedPointer<FrameBuffer> frame)
// reply fileinfo
auto f = clientCore_->GetBuffer(info, FBT_CLI_FILE_INFO, frame->fid);
if (!ClientCore::syncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); })) {
if (!ClientCore::syncInvoke(clientCore_, f)) {
qCritical() << QString(tr("send file %1 info failed.")).arg(info.fromPath);
doTask->file.close();
return;
@@ -237,7 +237,7 @@ void FileTrans::fbtTransDone(QSharedPointer<FrameBuffer> frame)
info.msg = QString(tr("recv file:%1 success.")).arg(downTask_->file.fileName());
qInfo() << info.msg;
auto f = clientCore_->GetBuffer(info, FBT_CLI_CAN_DOWN, frame->fid);
ClientCore::syncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); });
ClientCore::syncInvoke(clientCore_, f);
return;
}
qCritical() << QString(tr("recv file:%1 done sigal, but file not opened.")).arg(info.msg);
@@ -272,7 +272,7 @@ void FileTrans::fbtFileBuffer(QSharedPointer<FrameBuffer> frame)
InfoMsg info;
info.msg = downTask_->file.errorString();
auto f = clientCore_->GetBuffer(info, FBT_CLI_TRANS_FAILED, frame->fid);
ClientCore::syncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); });
ClientCore::syncInvoke(clientCore_, f);
downTask_->file.close();
}
downTask_->tranSize += ws;
@@ -351,12 +351,13 @@ void SendThread::run()
// shoule add abort action mark.
}
QMetaObject::invokeMethod(cliCore_, [this, frame] {
frame->sendRet = cliCore_->Send(frame);
if (frame->call) {
frame->call(frame);
}
});
// QMetaObject::invokeMethod(cliCore_, [this, frame] {
// frame->sendRet = cliCore_->Send(frame);
// if (frame->call) {
// frame->call(frame);
// }
// });
++curSendCount_;
if (!isSuccess_) {
@@ -372,7 +373,7 @@ void SendThread::run()
InfoMsg info;
auto f = cliCore_->GetBuffer(info, FBT_CLI_TRANS_DONE, task_->task.remoteId);
ClientCore::syncInvoke(cliCore_, [this, f]() { return cliCore_->Send(f); });
ClientCore::syncInvoke(cliCore_, f);
task_->file.close();
task_->state = TaskState::STATE_FINISH;
}

View File

@@ -2,11 +2,10 @@
#define FILETRANS_H
#include <QFile>
#include <QFuture>
#include <QMap>
#include <QMutex>
#include <QVector>
#include <QFuture>
#include <QPromise>
#include "ClientCore.h"
@@ -50,7 +49,7 @@ public:
void sendCall(QSharedPointer<FrameBuffer> frame);
private:
bool isSuccess_{ false };
bool isSuccess_{false};
ClientCore* cliCore_;
quint32 curSendCount_{0};
QSharedPointer<DoTransTask> task_;

View File

@@ -19,7 +19,7 @@ bool RemoteFile::GetHome()
{
InfoMsg info;
auto frame = cliCore_->GetBuffer(info, FBT_CLI_ASK_HOME, cliCore_->GetRemoteID());
return ClientCore::syncInvoke(cliCore_, [this, frame]() { return cliCore_->Send(frame); });
return ClientCore::syncInvoke(cliCore_, frame);
}
bool RemoteFile::GetDirFile(const QString& dir)
@@ -27,5 +27,5 @@ bool RemoteFile::GetDirFile(const QString& dir)
InfoMsg info;
info.msg = dir;
auto frame = cliCore_->GetBuffer(info, FBT_CLI_ASK_DIRFILE, cliCore_->GetRemoteID());
return ClientCore::syncInvoke(cliCore_, [this, frame]() { return cliCore_->Send(frame); });
return ClientCore::syncInvoke(cliCore_, frame);
}