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. Component as parameter of a signal or function
Forum Updated to NodeBB v4.3 + New Features

Component as parameter of a signal or function

Scheduled Pinned Locked Moved QML and Qt Quick
4 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
    antonio
    wrote on last edited by
    #1

    How can I pass my own Component as a parameter in a signal or a function? or how can I define my own type that can be recognized by QtQuick?

    This is MyItem.qml:

    @import QtQuick 1.0

    Item{
    property int index
    property int type
    property string text
    }@

    and this is my signal signature:

    @signal sendData(MyItem myItem)@

    I have tried, but it doesn't works

    Thanks

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jdowner
      wrote on last edited by
      #2

      Not sure what the correct answer is, but you may be able to use a variant in your signal signature.

      @
      Rectangle {
      height: 600
      width: 800
      MouseArea {
      signal fire(variant item)

      anchors.fill: parent
      onClicked: {
        console.log("pressed")
        var component = Qt.createComponent("MyItem.qml")
        var object = component.createObject(parent, {'name':'bob'})
        fire(object)
      }
      
      onFire: {
        console.log('fired ' + item.name)
      }
      

      }
      }
      @

      where MyItem.qml is

      @
      import QtQuick 1.0

      Item {
      property string name
      }
      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        antonio
        wrote on last edited by
        #3

        Very good, that's the solution of my problem, Thanks

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jdowner
          wrote on last edited by
          #4

          I have created an updated gist of this example,

          https://gist.github.com/4697780

          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