#include #include #include #include "parser/IParser.h" class TcpServerWorker : public QObject { Q_OBJECT public: TcpServerWorker(Parser_ptr parser, QObject* parent = nullptr) : QObject(parent) { _parser = std::move(parser); //Initialize the server server = new QTcpServer(this); connect(server, &QTcpServer::newConnection, this, &TcpServerWorker::handleNewConnection); } bool startServer(quint16 port) { return server->listen(QHostAddress::Any, port); } signals: void log(Log_ptr log); //uncrustify off private slots: //uncrustify on void handleNewConnection() { QTcpSocket* clientSocket = server->nextPendingConnection(); connect(clientSocket, &QTcpSocket::readyRead, this, [this, clientSocket]() { while(clientSocket->canReadLine()) { emit log(_parser->parse(clientSocket->readLine())); } }); } private: QTcpServer* server; Parser_ptr _parser; };