Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Receiving signals emitted by Repeater item
Forum Updated to NodeBB v4.3 + New Features

[Solved] Receiving signals emitted by Repeater item

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 4.2k 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.
  • S Offline
    S Offline
    stevenhurd
    wrote on last edited by
    #1

    Is there a way to receive a signal from an item created by a Repeater in the QML itself? Consider the following simplified example:

    @Rectangle {
    …
    Repeater {
    model: cppModel
    delegate: SimpleDelegate{}
    }
    }

    // SimpleDelegate.qml
    Item{
    …
    signal itemSignal(int index)
    …
    }@

    Is there a way to receive itemSignal somewhere where I can then operate on the item and, most likely, all the other items in the repeater as well? So far I haven’t been able to figure out how to handle this scenario without involving the C++ model.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daliusd
      wrote on last edited by
      #2

      I think you can accomplish that using connect (http://doc.qt.digia.com/qt/qmlevents.html#connecting-signals-to-methods-and-signals).

      Here is my guess:

      @delegate: SimpleDelegate{
      Component.onCompleted: {
      itemSignal.connect(someFunction)
      }
      }@

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on last edited by
        #3

        Certainly. You might want to read up on how to do signal and slot connections with [removed]
        http://doc.qt.digia.com/qt/qmlevents.html

        The most relevant example is this one:
        @
        Rectangle {
        id: forwarder
        width: 100; height: 100

         signal send()
         onSend: console.log("Send clicked")
        
         MouseArea {
             id: mousearea
             anchors.fill: parent
             onClicked: console.log("MouseArea clicked")
         }
         Component.onCompleted: {
             mousearea.clicked.connect(send)
         }
        

        }
        @

        Just connect your itemSignal to a function in the SimpleDelegate::onCompleted handler. (or alternatively in the Repeater::onItemAdded handler)

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

          Yes, thank you! I was under the mistaken impression that I needed Connections items to implement signals and slots in QML. This solution works perfectly.

          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