Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gamera_videos_no_ui
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liusq
gamera_videos_no_ui
Commits
a9aefd69
Commit
a9aefd69
authored
Sep 09, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mqtt断线重连,配置修改重新创建连接02
parent
8a850c09
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
MqttSubscriber.cpp
+4
-3
No files found.
MqttSubscriber.cpp
View file @
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 从远程云端拉取配置
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment