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 timeout signal isn't called when a local event loop is running
Forum Update on Monday, May 27th 2025

QTimer timeout signal isn't called when a local event loop is running

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 1.4k 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
    robinfaury
    wrote on 19 Aug 2019, 09:53 last edited by
    #1

    Hi there,

    I need to refresh some data every second. So I use a QTimer to update my data. On my app I have a QMenu as popup. If I exec the QMenu, it run a local QEventLoop. Because of that, my QTimer isn't called.

    Should I need QThread in this case?

    Best regards,
    robin

    J 1 Reply Last reply 20 Aug 2019, 04:59
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 Aug 2019, 19:24 last edited by
      #2

      Hi and welcome to devnet,

      The local event loop created by your menu exec call handles the events in place of the main loop.

      One thing you can do is use the worker object approach and move you data collection code in a different thread.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • M Offline
        M Offline
        MrShawn
        wrote on 19 Aug 2019, 19:56 last edited by
        #3

        From the QMenu docs:
        "They can be executed either asynchronously with popup() or synchronously with exec()."

        So even though they are getting their own event loop, if you are calling it with exec() then it will stop your event loop that is calling it until it returns something. You should instead try calling it with popup() and connect signals and slots to handle any asynchronous events coming from your popup menu.

        Hope it helps.

        1 Reply Last reply
        3
        • R robinfaury
          19 Aug 2019, 09:53

          Hi there,

          I need to refresh some data every second. So I use a QTimer to update my data. On my app I have a QMenu as popup. If I exec the QMenu, it run a local QEventLoop. Because of that, my QTimer isn't called.

          Should I need QThread in this case?

          Best regards,
          robin

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 20 Aug 2019, 04:59 last edited by J.Hilk
          #4

          @robinfaury
          take a look at this example:

          int main(int argc, char *argv[])
          {
          
              QApplication a(argc, argv);
          
              QTimer t;
              QObject::connect(&t, &QTimer::timeout, []()->void{qDebug() <<QTime::currentTime().toString();});
              t.start(10);
          
              QDialog dia;
              dia.exec();
          
              return  a.exec();
          }
          

          you'll notice that the debug output does not stop. So simply calling exec on (in this case) QDialog doesn't block the signal handling.
          There has to be something different going on inside your code


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          5
          • R Offline
            R Offline
            robinfaury
            wrote on 20 Aug 2019, 16:06 last edited by robinfaury
            #5

            @MrShawn Yes I see the popup behaviors but I need a synchronous process and the update.

            @SGaist @J-Hilk I found my mistake
            My QMenu exec is called inside the lambda.

            QApplication a(argc, argv);
            
            QTimer t;
            QObject::connect(&t, &QTimer::timeout, []()->void {
                qDebug() <<QTime::currentTime().toString();
                QDialog dia;
                dia.exec();
            });
            t.start(10);
            
            return  a.exec();
            

            Thanks for everything!

            Update: How can I set the thread as SOLVED?

            A 1 Reply Last reply 20 Aug 2019, 16:15
            2
            • R robinfaury
              20 Aug 2019, 16:06

              @MrShawn Yes I see the popup behaviors but I need a synchronous process and the update.

              @SGaist @J-Hilk I found my mistake
              My QMenu exec is called inside the lambda.

              QApplication a(argc, argv);
              
              QTimer t;
              QObject::connect(&t, &QTimer::timeout, []()->void {
                  qDebug() <<QTime::currentTime().toString();
                  QDialog dia;
                  dia.exec();
              });
              t.start(10);
              
              return  a.exec();
              

              Thanks for everything!

              Update: How can I set the thread as SOLVED?

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 20 Aug 2019, 16:15 last edited by
              #6

              @robinfaury

              Update: How can I set the thread as SOLVED?

              With the button Topic Tools below the last post.

              Regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              1

              4/6

              20 Aug 2019, 04:59

              • Login

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