client.hpp 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <QDialog>
  2. #include <QComboBox>
  3. #include <QPushButton>
  4. #include <QMessageBox>
  5. #include <QLineEdit>
  6. #include <QTimer>
  7. #include <QLabel>
  8. #include <QString>
  9. #include <QThread>
  10. #include <thread>
  11. #include <string>
  12. class Client : public QDialog
  13. {
  14. Q_OBJECT
  15. QThread workerThread;
  16. public:
  17. class MessageHandler {
  18. public:
  19. MessageHandler(std::function<void()> cb) : m_cb(cb) {}
  20. void operator()() { m_cb(); }
  21. private:
  22. std::function<void()> m_cb;
  23. };
  24. Client(QWidget *parent = nullptr);
  25. Client(QWidget *parent, int count, char** arguments);
  26. ~Client();
  27. void start();
  28. void closeConnection();
  29. MessageHandler createMessageHandler(std::function<void()> cb);
  30. public slots:
  31. void sendMessage(const QString& s);
  32. void sendEncoded(std::string message);
  33. signals:
  34. void messageReceived(QString s);
  35. private:
  36. void handleMessages();
  37. int argc;
  38. char** argv;
  39. int m_client_socket_fd;
  40. };