1
votes

I want to listen to a signal emitted from the initialItem in QML StackView. And it seems that the way i think on how to do it is wrong.

StackView {
    id: stackView
    initialItem:{
            myHomeForm{
               onMySignal{
                myArray=signalArray
               }
            }
    }
    anchors.fill: parent
}

The documentation only says on how to set a property but none on listening to a signal Please help thank you very much

1

1 Answers

3
votes

You can make the connection in Component.onCompleted through connect:

import QtQuick 2.9
import QtQuick.Controls 2.2

ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480
    title: qsTr("Stack")

    StackView {
        id: stackView
        initialItem: Page {
            id: page
            anchors.fill: parent
            signal mySignal()
            Button {
                text: qsTr("Click me")
                anchors.centerIn: parent
                onClicked: page.mySignal()
            }
        }
        anchors.fill: parent
        Component.onCompleted: initialItem.mySignal.connect(onMySignal)
        function onMySignal(){
            console.log("onMySignal")
        }
    }
}