123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #ifndef MQTTTHREAD_H
- #define MQTTTHREAD_H
- #include <QThread>
- #include <QString>
- #include <QStringList>
- #include "./mqtt/mqttclient.h"
- class MqttClient;
- class MqttThread : public QThread
- {
- Q_OBJECT
- public:
- MqttThread(QObject *parent = nullptr);
- ~MqttThread();
- void stopThread();
- void sendMqttMessage(const QString &topic, const QByteArray &message, quint8 qos, bool isRetainedMsg);
- void setConnectionInfo(const QString &hostname, quint16 port, const QString &username, const QString &password, const QString &clientId, const QStringList &topicsToSubscribe);
- MqttClient *getMqttClient() const;
- signals:
- void mqttConnected();
- // 转发 MQTT 消息接收信号
- void messageAndTopicReceived(const QByteArray &message, const QMqttTopicName &topic);
- void sendMessageRequested(const QString &topic, const QByteArray &message, quint8 qos, bool isRetainedMsg);
- protected:
- void run() override;
- private:
- MqttClient *mqttClient = nullptr;
- QString m_hostname;
- quint16 m_port;
- QString m_username;
- QString m_password;
- QString m_clientId;
- QStringList m_topicsToSubscribe;
- bool m_stopFlag = false;
- };
- #endif // MQTTTHREAD_H
|