websocketclient.h 936 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef WEBSOCKETCLIENT_H
  2. #define WEBSOCKETCLIENT_H
  3. #include <QObject>
  4. #include <QTcpSocket>
  5. #include <QSslError>
  6. #include <QList>
  7. #include <QString>
  8. #include <QUrl>
  9. #include <QtWebSockets/QWebSocket>
  10. QT_FORWARD_DECLARE_CLASS(QWebSocket)
  11. class WebsocketClient : public QObject
  12. {
  13. Q_OBJECT
  14. public:
  15. explicit WebsocketClient(QObject *parent = nullptr,
  16. QString ip="",
  17. quint16 port=0,
  18. QString termId="",
  19. QString termKey="");
  20. void reset();
  21. signals:
  22. void getData(QString data);
  23. void SoClosed();
  24. private slots:
  25. void onConnected();
  26. void onTextMessageReceived(const QString &message);
  27. void closeConnection();
  28. private:
  29. QTcpSocket *so;
  30. QString Ip;
  31. quint16 Port;
  32. QString TermId;
  33. QString TermKey;
  34. QUrl m_url;
  35. QWebSocket m_websocket;
  36. };
  37. #endif // WEBSOCKETCLIENT_H