#include "SocketClientUtil.h" #include "utils/ByteUtil.h" SocketClientUtil::SocketClientUtil(QObject *parent) : QObject(parent) { QObject::connect(&objClient, &QTcpSocket::readyRead, this, &SocketClientUtil::readData); } void SocketClientUtil::connect(QString host, int port) { this->host = host; this->port = port; objClient.connectToHost(this->host, this->port); } void SocketClientUtil::closeConnect() { objClient.close(); } QByteArray SocketClientUtil::getResponse() { return this->response; } void SocketClientUtil::sendData(QByteArray data) { // data.append(0x0D).append(0x0A); // 自动加\r\n标识一帧结束 objClient.write(data); } void SocketClientUtil::readData() { QByteArray buffer = objClient.readAll(); response.append(buffer); if (response.size() >= 320 * 240 * 3) { emit this->responseReaded(); } }