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. How can I send a signal to an Item which is inside a Loader ?
Forum Updated to NodeBB v4.3 + New Features

How can I send a signal to an Item which is inside a Loader ?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #1

    How can I send a signal to an Item which is inside a Loader ?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      AFAIK, you can do it in following ways:

      1. Using "Connect()":http://doc.qt.io/qt-5/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals
      2. Using "Connections()":http://doc.qt.io/qt-5/qml-qtqml-connections.html

      An example :
      @
      Item {
      id: item
      width: 100
      height: 150

      signal sendMessage(string msg)
      
      Loader {
          id: loader
          width: 100
          height: 100
          sourceComponent: comp
          Component.onCompleted: item.sendMessage.connect(loader.item.setText) //comment Component.onCompleted if using Connections and vice versa
      }
      

      // Connections {
      // target: item
      // onSendMessage: {
      // loader.item.setText(msg)
      // }
      // }

      Component {
          id: comp
          Rectangle {
              anchors.fill: parent
              color: "red"
              function setText(msg) {
                  mytext.text = msg
              }
      
              Text {
                  id: mytext
                  anchors.centerIn: parent
              }
          }
      }
      
      Button {
          text: "Click Me"
          y: 110
          onClicked: item.sendMessage("Hello Qt")
      }
      

      }
      @

      157

      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