From 02b759b406398ac81e19aabeb4e310fa87a12ecf Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Mon, 6 Apr 2020 22:22:26 +0200 Subject: [PATCH] minor patch --- ScStwLibraries/scstwclient.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ScStwLibraries/scstwclient.cpp b/ScStwLibraries/scstwclient.cpp index d45c5ea..03e4dcf 100644 --- a/ScStwLibraries/scstwclient.cpp +++ b/ScStwLibraries/scstwclient.cpp @@ -22,7 +22,7 @@ ScStwClient::ScStwClient() : QObject(nullptr) connect(this->socket, &QAbstractSocket::stateChanged, this, &ScStwClient::handleSocketStateChange); - connect(this->socket, &QTcpSocket::readyRead, + connect(this->socket, &QAbstractSocket::readyRead, this, &ScStwClient::handleReadyRead); @@ -109,7 +109,7 @@ QVariantMap ScStwClient::sendCommand(int header, QJsonValue data, int timeout) { if(this->state != CONNECTED) return {{"status", ScStw::NotConnectedError}, {"data", "not connected"}}; - return this->sendCommand(header, data, timeout, false); + return this->sendCommand(header, data, timeout, true); } QVariantMap ScStwClient::sendCommand(int header, QJsonValue data, int timeout, bool useTerminationKeys) { @@ -142,12 +142,10 @@ QVariantMap ScStwClient::sendCommand(int header, QJsonValue data, int timeout, b timer->start(timeout); //write data - if(useTerminationKeys) { - socket->write("" + jsonRequest.toLatin1() + ""); - } - else { - socket->write(jsonRequest.toLatin1()); - } + if(useTerminationKeys) + socket->write(ScStw::SOCKET_MESSAGE_START_KEY + jsonRequest.toUtf8() + ScStw::SOCKET_MESSAGE_END_KEY); + else + socket->write(jsonRequest.toUtf8()); //wait for an answer to finish (programm gets stuck in here) loop->exec(); @@ -172,7 +170,7 @@ QVariantMap ScStwClient::sendCommand(int header, QJsonValue data, int timeout, b if(!replyFound) { // some internal error occured - return {{"status", 900}, {"data", ""}}; + return {{"status", ScStw::Error}, {"data", ""}}; } if(timer->remainingTime() == -1){