Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Calling slot only once, even if multiple signals request it

    General and Desktop
    3
    4
    1143
    Loading More Posts
    • 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
      eddyilg last edited by

      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 Reply Quote 0
      • M
        MuldeR last edited by

        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 Reply Quote 0
        • E
          eddyilg last edited by

          Is that the common way to do it then?

          Best,

          Eddy

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • First post
              Last post