我想听QML initialItem
中StackView
发出的信号。而且看来我认为如何做错了。
StackView {
id: stackView
initialItem:{
myHomeForm{
onMySignal{
myArray=signalArray
}
}
}
anchors.fill: parent
}
该文档仅说明如何设置属性,而没有说明如何监听信号 请非常感谢您
答案 0 :(得分:1)
您可以在Component.onCompleted
到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")
}
}
}