mqttthread.h 851 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef MQTTTHREAD_H
  2. #define MQTTTHREAD_H
  3. #include <QThread>
  4. #include <qmqtt.h>
  5. #include <QTimer>
  6. #include <QJsonDocument>
  7. #include <QJsonArray>
  8. #include <QJsonObject>
  9. #include <QJsonValue>
  10. #include <QJsonParseError>
  11. class MqttInfo{
  12. public:
  13. explicit MqttInfo(QString t="",QByteArray d=""){
  14. topic = t;
  15. data = d;
  16. }
  17. QString topic;
  18. QByteArray data;
  19. };
  20. class MqttThread : public QThread
  21. {
  22. Q_OBJECT
  23. public:
  24. explicit MqttThread(QObject *parent = nullptr);
  25. ~MqttThread();
  26. void run();
  27. signals:
  28. void mqttLog(QString log);
  29. void sendDevData(QString data);
  30. public slots:
  31. void time_out();
  32. void onConnected();
  33. void onReceived(const QMQTT::Message &message);
  34. private:
  35. QTimer *timer;
  36. QMQTT::Client *m_client;
  37. bool keep;
  38. QList<MqttInfo>mqttDataList;
  39. };
  40. #endif // MQTTTHREAD_H