2
votes

I want to ask simple question for quick solution. I have ListView and Button in main.qml and Component in closingtaskdelage.qml. Here is file main.qml:

ListView
{
    id: grid

    delegate:mydelegate


    model: mymodel
    spacing: 5
    orientation:ListView.Vertical
    Layout.preferredWidth: width_commmon
    Layout.preferredHeight: height_body
    Layout.maximumHeight: 800
    Layout.alignment: Qt.AlignHCenter
    // highlightFollowsCurrentItem: false
    focus: true

    ClosingTaskModel
    {
        id:mymodel
    }

    ClosingTaskDelegate
    {
        id:mydelegate
    }


}

Button
{
    id:finishbutton
    Layout.alignment: Qt.AlignHCenter
    Layout.preferredWidth: width_commmon
    Layout.preferredHeight:height_endbutton
    text: "İş Emrini Tamamla"
    onClicked:
    {
         // console.log((grid.children["border1"]).id);
    }
}

and file ClosingTaskDelegate.qml:

Component
{
    id:component1

    Rectangle
    {
        signal sendMenuValuestoJS
        height: 200
        width: 200

        Text
        {
            id:text1;
            text:header;
            height:parent.height/2
            //    width: parent.width

            anchors.horizontalCenter:parent.horizontalCenter;
            font.pointSize:20;
            color:"red";
            //  height:parent.height/2
            //  width: parent.width
        }
    }
}

Don't care about details. My main problem is: When onClickButton() in main.qml occurs, signal sendMenuValuestoJS() must be triggered. This signal must send string value as parameter (i.e. send Text). I can't access signal from main.qml. I have defined signal in the Component, but I get following runtime QML error:

Component objects cannot declare new signals.

How do I connect signal to some function?

2

2 Answers

2
votes

What about to to use Connections?

Here is the idea,

/* main.qml */
Rectangle {
    width: 200
    height: 200

    MouseArea {
        id: mouse
        anchors.fill: parent
    }

    Click {
        id: click
        targetto: mouse
    }
}

/* Click.qml */
Item {
    property variant targetto
    Connections {
        target: targetto
        onClicked: console.log("CLICKED!");
    }
}
0
votes

Here is example from official Qt webiste in Signal Handler Attributes chapter.