#include #include #include #include #include #include #include #include #include #include #include #include #include #include static constexpr int MESSAGE_UPDATE_TYPE = 1; static constexpr int COMMANDS_UPDATE_TYPE = 2; typedef std::map CommandMap; typedef QVector StringVec; Q_DECLARE_METATYPE(StringVec) class Client : public QDialog { Q_OBJECT QThread workerThread; public: class MessageHandler { public: MessageHandler(std::function cb) : m_cb(cb) {} void operator()() { m_cb(); } private: std::function m_cb; }; Client(QWidget *parent = nullptr); Client(QWidget *parent, int count, char** arguments); ~Client(); void start(); void closeConnection(); MessageHandler createMessageHandler(std::function cb); public slots: void sendMessage(const QString& s); void sendEncoded(std::string message); signals: void messageReceived(int t, QString s,QVector args); private: void handleMessages(); int argc; char** argv; int m_client_socket_fd; CommandMap m_commands; };