main.qml:
import QtQuick 2.11
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
x: 200
y: 200
visible: true
Component {
id: firstViewComponent
FirstView {
id: firstView
}
}
StackView {
id: stackView
anchors.fill: parent
Component.onCompleted: push(firstViewComponent)
}
Timer {
interval: 1000
running: true
onTriggered: stackView.pop()
}
}
FirstView.qml:
Rectangle {
id: view
StackView.onDeactivating: console.log('view: view is deactivating')
ListModel {
id: aModel
ListElement {
name: 'Element 0'
}
ListElement {
name: 'Element 1'
}
}
ListView {
id: listView
model: aModel
delegate: Rectangle {
id: listViewDelegate
Connections {
target: view.StackView // <---- DOESN'T WORK
onDeactivating: console.log('delegate ' + index + ': needs to do some housekeeping now')
}
}
}
}
我有一个由main.qml中的StackView实例化的视图。StackView将信号StackView.onDeactivating附加到视图上。是否有办法从与信号附加对象不同的对象连接到该信号?当视图弹出时,我需要在listViewDelegate中进行一些清理。
我可以让视图发出自己的信号,并让委托响应该信号。但是我想知道是否有一种方法可以连接到附加的信号:StackView.onDeactivating,来自不同的对象(listViewDelegate)。
myView
?请提供一个 [mcve]。 - eyllanesc