#ifndef MQTTTHREAD_H #define MQTTTHREAD_H #include #include #include #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); 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); 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