Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138645

Allow multiple listeners for one QML signal

XMLWordPrintable

    • Icon: User Story User Story
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • None
    • QPA: Android

      Requirements:

      • I want to be able to trigger N actions from 1 QML signal
      • I want to be able to selectively dsconnect those actions from the QML signal

      Why:

      Sometimes I have a QML signal that will impact multiple classes, or just call multiple functions. For that, I want to be able to connect multiple things to QML signals.

      This helps keep code easy to read on the user side, and avoid messy code if e.g. some code triggered by a signal should only happen when certain conditions are met - this would be easier to handle by disconnecting and reconnecting the signal than by maintaining a flag that the signal handler checks each time it is triggered.

      How:

      In QAndroidViewSignalManager:

      1. Instead of storing a QMap<int, ConnectionInfo>, store QMap<int, vector<ConnectionInfo>>
        1. Same for queued connections post-QTBUG-137057
      2. In qt_metacall where the signal listener is called, instead loop through the stored vector<ConnectionInfo> and invoke the listeners.
      3. in addConnection():
        1. Remove the check for duplicate connections.
        2. Instead of inserting ConnectionInfo directly to the Map, get the vector from the map and push into the vector.
      4. In qt_metacall():
        1. Wrap the current implementation in a for-loop cycling through the registered listeners for the triggered signal.
      5. in hasConnection():
        1. Instead of checking each element of the map for the requested ID, check each vector in each element.
        2. For queued connections, do the same. (post-QTBUG-137057)
      6. in removeConnection():
        1. Instead of directly calling QMap::removeIf() for the given ID, remove the ID from whichever vector contains it.
          1. for queued connections, do the same. (post-QTBUG-137057)
      7. in onViewStatusChanged (post- QTBUG-137057):
        1. Nested loop through the queued info vectors.
      8. in queueConnection() (post-QTBUG-137057):
        1. Push into the vector instead of the map.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qtandroidteam Qt Android Team
            pevirkku Petri Virkkunen
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes