Solved QTimer stop working after connecting mqtt
-
Hi,
I have q QTimer as :
reset_history = new QTimer(this); connect(reset_history, SIGNAL(timeout()) , this, SLOT(resetHistoryList())); reset_history->start(8000);
it is working untill I connecting to the mqtt and stop working.
An idea ?
-
Does the
QTimer
stop or does some process stop, which was triggered by your timer? -
@Pl45m4 no . it looks like a strange event. looks a bug
-
@RahibeMeryem said in QTimer stop working after connecting mqtt:
it looks like a strange event. looks a bug
You should first check whether you block the event loop.
Can you show how you connect to mqtt? -
void Widget::connectMqtt() { if (!ui->MqttHostName->text().isEmpty()) hostname = ui->MqttHostName->text(); else hostname = "localhost"; MqttUserName = ui->usernameMqtt->text(); //MQTT c_client = new QMqttClient(this); qDebug() << "CENTRAL connecting....." << endl; c_client->setHostname(hostname); c_client->setPort(1883); c_client->setClientId("Mac-01"); c_client->setUsername(ui->usernameMqtt->text()); c_client->setPassword(ui->passwordMqtt->text()); c_client->setCleanSession(false); c_client->setKeepAlive(30); connect(c_client, &QMqttClient::stateChanged, this, &Widget::mq_status_changed); connect(c_client, &QMqttClient::connected, this, &Widget::mq_succesfully_connected); connect(c_client, &QMqttClient::pingResponseReceived, this, &Widget::mq_ping_received); connect(c_client, &QMqttClient::messageReceived, this, &Widget::mq_message_received); connect(c_client, &QMqttClient::disconnected, this, &Widget::mq_reconnect); c_client->connectToHost(); }
This is the mqtt connection part.
-
try debug and set a breakpoint at end c_client->connectToHost();
orc_client->connectToHost(); qDebug() << "connectToHost";
and check if thread not locked waiting for something in other part of your code
-
@RahibeMeryem Is your app still responsive (not hanging) after connect?
-
@jsulm Yes its working like a charm, all parts.
Only QTimers part are not working stopping..
-
@Diackne qDebug() << "connectToHost"; printed on the log screen no problem.
Problem looks deeper. couldn't find the reason why
-
When I create QTimer and connect in a separate Thread all is working now.