Component as parameter of a signal or function



  • 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



  • 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
    }
    @



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



  • I have created an updated gist of this example,

    https://gist.github.com/4697780


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.