client.hpp 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. class Client : public QDialog
  12. {
  13. Q_OBJECT
  14. QThread workerThread;
  15. public:
  16. class MessageHandler {
  17. public:
  18. MessageHandler(std::function<void()> cb) : m_cb(cb) {}
  19. void operator()() { m_cb(); }
  20. private:
  21. std::function<void()> m_cb;
  22. };
  23. Client(QWidget *parent = nullptr);
  24. Client(QWidget *parent, int count, char** arguments);
  25. ~Client();
  26. void start();
  27. void closeConnection();
  28. MessageHandler createMessageHandler(std::function<void()> cb);
  29. public slots:
  30. void sendMessage(const QString& s);
  31. signals:
  32. void messageReceived(QString s);
  33. private:
  34. void handleMessages();
  35. int argc;
  36. char** argv;
  37. int m_client_socket_fd;
  38. };