Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. 50 signal/slots
Forum Updated to NodeBB v4.3 + New Features

50 signal/slots

Scheduled Pinned Locked Moved Solved Qt 6
6 Posts 5 Posters 247 Views 2 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.
  • servant 0S Offline
    servant 0S Offline
    servant 0
    wrote last edited by servant 0
    #1

    Hello. What will run faster, 50 signals connected to their own slot, or 1 signal reused 50 times with 1 slot? I prefer the first option because it is a lot less redundant code writing for me. I setup the 50 signals to emit their object name as a QString and call findChild on it to update the text on a label in the slot (it's for a hardware status page). As I understand it, an emit signal is just like calling the slot function directly.

    J.HilkJ JonBJ 2 Replies Last reply
    0
    • A Offline
      A Offline
      ankou29666
      wrote last edited by
      #2

      it's equal, one signal emitted means one function call. the count of slots connected to one signal (or conversely) has no impact on performance

      1 Reply Last reply
      1
      • B Offline
        B Offline
        Ben Campbell-Wallis
        wrote last edited by
        #3

        Hi @servant-0 , I think your scenario in practice will be the same as each signal contains a look up to its connected slot.
        So each emit is only connected to one slot - i.e: each emit only iterates its own connection list (one slot).
        The other way round is 50 signals each with their own slot incurs exactly the same per-signal overhead - i.e: one slot per emit.

        1 Reply Last reply
        1
        • servant 0S Offline
          servant 0S Offline
          servant 0
          wrote last edited by
          #4

          Awesome! Thank you so much @ankou29666 and @Ben-Campbell-Wallis. I will avoid redundant code and use the dynamic 1 slot/signal approach then.

          1 Reply Last reply
          0
          • servant 0S servant 0 has marked this topic as solved
          • servant 0S servant 0

            Hello. What will run faster, 50 signals connected to their own slot, or 1 signal reused 50 times with 1 slot? I prefer the first option because it is a lot less redundant code writing for me. I setup the 50 signals to emit their object name as a QString and call findChild on it to update the text on a label in the slot (it's for a hardware status page). As I understand it, an emit signal is just like calling the slot function directly.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote last edited by
            #5

            Usually both variants should be about the same time. You would have to benchmark it.

            That said:
            @servant-0 said in 50 signal/slots:

            I setup the 50 signals to emit their object name as a QString and call findChild on it to update the text on a label in the slot

            findChild is incredibly slow, depending on your UI magnitudes slower than other parts of your code. I would recommend using it as little as possible and not regularly in slots


            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
            3
            • servant 0S servant 0

              Hello. What will run faster, 50 signals connected to their own slot, or 1 signal reused 50 times with 1 slot? I prefer the first option because it is a lot less redundant code writing for me. I setup the 50 signals to emit their object name as a QString and call findChild on it to update the text on a label in the slot (it's for a hardware status page). As I understand it, an emit signal is just like calling the slot function directly.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote last edited by
              #6

              @servant-0 said in 50 signal/slots:

              I setup the 50 signals to emit their object name as a QString and call findChild on it to update the text on a label in the slot

              All as @J.Hilk has written about findChild(). Also it depends hugely on whether your target widget is "close" in the hierarchy to the widget you call findChild() on. If that is "high up" it has a lot of searching to do if there are a lot of descendent widgets.

              It sounds like you have a backend data layer which emits a signal when it changes and passes the value of what will be used as a widget's objectName() to indicate which widget to update? If so that is not ideal for decoupling data from UI.

              You might like to look at QDataWidgetMapper for a means of tying widgets to data values (works in both directions, though you may only need data->widget direction). For that you would store your data values in anything derived from a QAbstractItemModel and any time that data changes internally a signal is sent and the corresponding widget is updated (without lookup).

              1 Reply Last reply
              3

              • Login

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