1.增加取图后默认保存图像,YUV和JPG各保存一张; 2.修复出现QTcpSocket对象的问题和QTcpSocket对象导致的线程安全问题
This commit is contained in:
@@ -64,7 +64,6 @@ MainWidget::MainWidget(QWidget* parent) :
|
||||
qDebug() << "The client IP address is back board or all board";
|
||||
isBackBoardOrAllBoard = clientId;
|
||||
}
|
||||
|
||||
stopMdnsService();
|
||||
connectedClientsCount ++;
|
||||
updateServerButtonText();
|
||||
@@ -87,11 +86,26 @@ MainWidget::MainWidget(QWidget* parent) :
|
||||
});
|
||||
|
||||
QThread* thread = new QThread(this);
|
||||
#if TEST_TCP_MOVE_TO_MAIN
|
||||
ClientHandler* handler = new ClientHandler(socket, frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
|
||||
frontBoardDevInfoJson, frontBoardLicenseJson,
|
||||
backBoardOneClickTest, backBoardTest, backBoardFuncConfig, backBoardDevInfoJson,
|
||||
backBoardUuidJson, getPicJson, getVideoJson, clientId, isBackBoardOrAllBoard, nullptr);
|
||||
|
||||
#else
|
||||
ClientHandler* handler = new ClientHandler(frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
|
||||
frontBoardDevInfoJson, frontBoardLicenseJson,
|
||||
backBoardOneClickTest, backBoardTest, backBoardFuncConfig, backBoardDevInfoJson,
|
||||
backBoardUuidJson, getPicJson, getVideoJson, clientId, isBackBoardOrAllBoard, nullptr);
|
||||
/*
|
||||
* 一定要先取消父对象,否则报错:QObject::moveToThread: Cannot move objects with a parent
|
||||
* 父对象负责管理子对象的生命周期,如果子对象被移动到其他线程,可能会导致线程安全问题或不一致的对象状态
|
||||
*/
|
||||
socket->setParent(nullptr);
|
||||
// 将 socket 移动到新的线程中
|
||||
socket->moveToThread(thread);
|
||||
// 将 socket 传递到 handler
|
||||
handler->initialize(socket);
|
||||
#endif
|
||||
// 将 ClientHandler 移到线程池中的线程
|
||||
handler->moveToThread(thread);
|
||||
|
||||
@@ -103,8 +117,7 @@ MainWidget::MainWidget(QWidget* parent) :
|
||||
backBoardUuidJson, getPicJson, getVideoJson, nullptr);
|
||||
// 将 DataHandler 移到线程池中的线程
|
||||
dataHandler->moveToThread(thread);
|
||||
|
||||
|
||||
#if TEST_TCP_MOVE_TO_MAIN
|
||||
// 将sendData信号连接到主线程中的槽上
|
||||
connect(handler, &ClientHandler::sendData, this, [socket](const QByteArray& data, int isBoardType) {
|
||||
/*socket->write(data);
|
||||
@@ -128,7 +141,9 @@ MainWidget::MainWidget(QWidget* parent) :
|
||||
socket->write(prefix);
|
||||
socket->flush();
|
||||
});
|
||||
|
||||
#else
|
||||
connect(handler, &ClientHandler::sendData, handler, &ClientHandler::onSendData, Qt::QueuedConnection);
|
||||
#endif
|
||||
connect(handler, &ClientHandler::startTimeout, this, [this, clientId](int timeout) {
|
||||
this->onStartTimeout(clientId, timeout);
|
||||
});
|
||||
@@ -140,8 +155,7 @@ MainWidget::MainWidget(QWidget* parent) :
|
||||
connect(handler, &ClientHandler::clientDisconnected, this, &MainWidget::onClientDisconnected);
|
||||
connect(handler, &ClientHandler::allItemsProcessed, this, &MainWidget::onAllItemsProcessed);
|
||||
connect(handler, &ClientHandler::selectClientDisconnected, this, &MainWidget::onDisconnectClient);
|
||||
|
||||
|
||||
|
||||
dataHandlers[clientId] = dataHandler;
|
||||
connect(handler, &ClientHandler::dataReceived, dataHandler, &DataHandler::handleData);
|
||||
connect(dataHandler, &DataHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
|
||||
@@ -161,12 +175,9 @@ MainWidget::MainWidget(QWidget* parent) :
|
||||
// 启动新的线程
|
||||
thread->start();
|
||||
|
||||
connect(handler, &ClientHandler::startReadTimer, this, &MainWidget::startClientReadTimer);
|
||||
connect(handler, &ClientHandler::stopReadTimer, this, &MainWidget::stopClientReadTimer);
|
||||
//handler->getClientId() == handler->preVideoClientId
|
||||
//qDebug() << "---- handler->getClientId():" << handler->getClientId();
|
||||
//qDebug() << "---- handler->preVideoClientId:" << handler->preVideoClientId;
|
||||
connect(this, &MainWidget::openFocusWindowRequested, dataHandler, &DataHandler::handleOpenFocusWindow);
|
||||
connect(handler, &ClientHandler::startReadTimer, this, &MainWidget::startClientReadTimer);
|
||||
connect(handler, &ClientHandler::stopReadTimer, this, &MainWidget::stopClientReadTimer);
|
||||
connect(this, &MainWidget::openFocusWindowRequested, dataHandler, &DataHandler::handleOpenFocusWindow);
|
||||
|
||||
// 创建和管理定时器
|
||||
QTimer* readTimer = new QTimer(this);
|
||||
@@ -1100,24 +1111,6 @@ void MainWidget::stopMdnsService()
|
||||
mServiceProvider->stopServiceBroadcast();
|
||||
}
|
||||
|
||||
#if TEST_UDP_BROADCAST
|
||||
void MainWidget::sendMulticastMessage()
|
||||
{
|
||||
QByteArray datagram = "--------------------------------- Test multicast message from MainWidget";
|
||||
QHostAddress groupAddress("224.0.0.251");
|
||||
quint16 port = 5353;
|
||||
|
||||
qint64 sentBytes = multicastSocket->writeDatagram(datagram, groupAddress, port);
|
||||
if (sentBytes == -1) {
|
||||
qWarning() << "Failed to send multicast message:" << multicastSocket->errorString();
|
||||
}
|
||||
else {
|
||||
qDebug() << "Multicast message sentBytes:" << sentBytes;
|
||||
qDebug() << "Multicast message sent:" << datagram;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// 处理开始服务器按键点击事件
|
||||
void MainWidget::onStartServerClicked()
|
||||
{
|
||||
@@ -1192,7 +1185,6 @@ void MainWidget::onSendGetPicClicked()
|
||||
if (connectedClientsCount) {
|
||||
QPushButton* button = qobject_cast<QPushButton*>(sender());
|
||||
int itemIndex = button->property("getPicIndex").toInt();
|
||||
|
||||
if (itemIndex < 2) {
|
||||
button->setStyleSheet("background-color: green;");
|
||||
if (lastClickedGetPicCamIndex != -1 && lastClickedGetPicCamIndex != itemIndex) {
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include "../Network/ClientHandler.h"
|
||||
#include "../Network/httpClient.h"
|
||||
|
||||
|
||||
#include "../Network/mdns/qmdnsengine/include/server.h"
|
||||
#include "../Network/mdns/qmdnsengine/include/hostname.h"
|
||||
#include "../Network/mdns/qmdnsengine/include/provider.h"
|
||||
|
||||
Reference in New Issue
Block a user