Commit 2e9ea28b by 郭峰

Merge branch 'feature/mqtt-feature' into 'release'

mqtt断线重连,配置修改重新创建连接02

See merge request !17
parents c2d3e63e a9aefd69
......@@ -30,21 +30,21 @@ void MqttSubscriber::init(vides_data::MqttConfig &config,QString &httpUrl,QStrin
}, nullptr);
// 连接信号和槽
connect(this, &MqttSubscriber::connectionLostSignal, this, &MqttSubscriber::reconnectAndFetchConfig);
connect(this, &MqttSubscriber::connectionLostSignal, this, &MqttSubscriber::reconnectAndFetchConfig,Qt::QueuedConnection);
}
MqttSubscriber::MqttSubscriber(QObject* parent)
: QObject(parent), retryTimer(new QTimer(this)) {
retryTimer->setInterval(10000); // 设置重试间隔为10秒
retryTimer->setSingleShot(true); // 单次触发
connect(retryTimer, &QTimer::timeout, this, &MqttSubscriber::reconnectAndFetchConfig);
connect(retryTimer, &QTimer::timeout, this, &MqttSubscriber::reconnectAndFetchConfig,Qt::QueuedConnection);
}
MqttSubscriber::~MqttSubscriber() {
MQTTAsync_destroy(&client);
instance = nullptr;
}
s
void MqttSubscriber::start() {
retryTimer->stop(); // 确保每次开始连接前停止定时器
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
......@@ -94,6 +94,7 @@ void MqttSubscriber::onConnect(MQTTAsync_successData* response) {
}
void MqttSubscriber::reconnectAndFetchConfig() {
qInfo() << "重新连接并获取配置 ";
Common & instace= Common::getInstance();
vides_data::responseConfig re_config;
// 使用 HttpService 从远程云端拉取配置
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment