Qt MQTT and while loop
Solved
General and Desktop
-
wrote on 16 Jan 2019, 10:31 last edited by
Hello!
I' m using Qt Mqtt on Windows and I have troubles to publish a message in a while loop.
For example:
int n=0; while (n<5){ qDebug()<<Q_FUNC_INFO<<endl; mClient->publish(QMqttTopicName(topic.toString()),data.toByteArray()); Sleep(20000); n++; }
with this code, publishments are all made at the same time and after exiting the while loop. But this is not what I want, I would like a publishement every 2 seconds during the execution of the while loop.
Thank you in advance for telling me how to achieve this.
guigiidre
-
Hi and welcome to devnet,
You are blocking the event loop which explains what is going on.
A QTimer would likely be a cleaner approach. Let it timeout 5 times and then stop it.
-
wrote on 16 Jan 2019, 13:50 last edited by
Great, it works, Qtimer was the solution.
Thank you!
1/3