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. Calling slot only once, even if multiple signals request it
Qt 6.11 is out! See what's new in the release blog

Calling slot only once, even if multiple signals request it

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.6k 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.
  • E Offline
    E Offline
    eddyilg
    wrote on last edited by
    #1

    Hi,

    I have the following scenario:
    I have settings widgets A, B and C and and image rendering widget I. Then I have the following signal to slot connections:
    A.changed() -> I.render();
    B.changed() -> I.render();
    C.changed() -> I.render();

    Now the problem is that A also changes values of B and C. Thus, changing A results in 3 I.render() calls (one from A, one from B and one from C). How can I queue the call to I.render() and keep only one request in the queue() ? The QWidget update() function has a similar behavior AFAIK.

    I could possibly do it using QTimer, but is there a better way?

    Regards,

    Eddy

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      Yeah, that's how I would do it: Connect ABC.changed() not to I.render() directly, but instead to some other slot, like I.update(). This new slot will do nothing but enable a QTimer (in "single shot" mode!) - unless the timer is already enabled. Finally, your QTimer is connected to I.render().

      Alternatively, you could work with blockSignals(), in order to temporarily disable the signals of B and C when A fires. But that will introduce a lot of dependencies (A needs to take care of B and C now, for example).

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eddyilg
        wrote on last edited by
        #3

        Is that the common way to do it then?

        Best,

        Eddy

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          The QTimer is a common technique. One variant that you can use is to restart the timer rather than check if it's enabled so render will only be called after no changes happened after a while.

          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
          0

          • Login

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