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. Dropping signals

Dropping signals

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    goocreations
    wrote on last edited by
    #1

    I have a program that runs simulations, and every time my results update, a signal is emitted and I show the results in my GUI. This works perfectly if I run my simulations on real-time data (the signal is emitted every couple of minutes).

    However, when I run a benchmark on old data that I collected (not real-time anymore), my entire simulation takes about one minute, with all my signals (about 2 million) emitted within this one second. Hence, my GUI updates 2 million times in a single second.

    Is there anyway I can drop signals if there are so many emitted in a short time? I'm not sure how the Qt code is implemented, but I assume that with a Qt::QueuedConnection, all emitted signals are added to the end of the queue, and then one-by-one they are taken from the front of the queue and then processed. So the moment it checks for the next signal in the queue, if the queue has more than 1 signal, it should drop all of them and only take the last one.

    Disconnecting the signal and only updating the GUI at the end is not an option for me, since other processes rely on continues updates (even if every nth update is dropped).

    Is something like this possible?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      As far as I know you can't drop signals like you are describing. Your best bet would be to implement a way to not having to send so many signals. For example you could a timer that only periodically checks your data and then emit the signal.

      Queued connections are only added to a queue if the signal emitter and the signal receiver live in different threads, if your emitter lives in the same thread as your gui the slots are executed immediately.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goocreations
        wrote on last edited by
        #3

        Hmm, hoped there would be a clean solution. Just for interest sake, what exactly does QCoreApplication::removePostedEvents() do? Some other post suggested using this function for something similar. However, it doesn't seem to work in my situation.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          t3685
          wrote on last edited by
          #4

          More information here:
          http://qt-project.org/doc/qt-5/qcoreapplication.html#removePostedEvents

          In my opinion should consider just not sending as many signals as this is the main reason for your performance problems.
          All you need to do is modify the code where you retrieve your real time data and have some logic to reduce the number of emissions.
          Also it does not seem efficient to do work to process the real-time data only to drop it again moments later.

          Anyway, good luck!

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goocreations
            wrote on last edited by
            #5

            Yip, did that now. Just emitted every 100th signal. Thanks.

            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