Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTimer stop working after connecting mqtt
Forum Update on Monday, May 27th 2025

QTimer stop working after connecting mqtt

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 689 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RahibeMeryem
    wrote on last edited by
    #1

    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 ?

    Pl45m4P 1 Reply Last reply
    0
    • R RahibeMeryem

      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 ?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @RahibeMeryem

      Does the QTimer stop or does some process stop, which was triggered by your timer?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      R 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @RahibeMeryem

        Does the QTimer stop or does some process stop, which was triggered by your timer?

        R Offline
        R Offline
        RahibeMeryem
        wrote on last edited by
        #3

        @Pl45m4 no . it looks like a strange event. looks a bug

        jsulmJ 1 Reply Last reply
        0
        • R RahibeMeryem

          @Pl45m4 no . it looks like a strange event. looks a bug

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          2
          • jsulmJ jsulm

            @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?

            R Offline
            R Offline
            RahibeMeryem
            wrote on last edited by
            #5

            @jsulm

            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.

            jsulmJ 1 Reply Last reply
            0
            • DiackneD Offline
              DiackneD Offline
              Diackne
              wrote on last edited by
              #6

              try debug and set a breakpoint at end c_client->connectToHost();
              or

               c_client->connectToHost();
               qDebug() << "connectToHost";
              
              

              and check if thread not locked waiting for something in other part of your code

              R 1 Reply Last reply
              0
              • R RahibeMeryem

                @jsulm

                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.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @RahibeMeryem Is your app still responsive (not hanging) after connect?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                R 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @RahibeMeryem Is your app still responsive (not hanging) after connect?

                  R Offline
                  R Offline
                  RahibeMeryem
                  wrote on last edited by
                  #8

                  @jsulm Yes its working like a charm, all parts.

                  Only QTimers part are not working stopping..

                  1 Reply Last reply
                  0
                  • DiackneD Diackne

                    try debug and set a breakpoint at end c_client->connectToHost();
                    or

                     c_client->connectToHost();
                     qDebug() << "connectToHost";
                    
                    

                    and check if thread not locked waiting for something in other part of your code

                    R Offline
                    R Offline
                    RahibeMeryem
                    wrote on last edited by
                    #9

                    @Diackne qDebug() << "connectToHost"; printed on the log screen no problem.

                    Problem looks deeper. couldn't find the reason why

                    R 1 Reply Last reply
                    0
                    • R RahibeMeryem

                      @Diackne qDebug() << "connectToHost"; printed on the log screen no problem.

                      Problem looks deeper. couldn't find the reason why

                      R Offline
                      R Offline
                      RahibeMeryem
                      wrote on last edited by
                      #10

                      When I create QTimer and connect in a separate Thread all is working now.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved