Nominate our 2022 Qt Champions!

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

    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


  • 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: {
      var component = Qt.createComponent("MyItem.qml")
      var object = component.createObject(parent, {'name':'bob'})
    onFire: {
      console.log('fired ' +


    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,

Log in to reply