How to access objectName
of children of ApplicationWindow
?
With ApplicationWindow
:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
ApplicationWindow {
id: head
visible: true
width: 640
height: 480
Rectangle{ height:1; width: 1; objectName: "AA"}
Rectangle{ height:1; width: 1; objectName: "BB"}
Component.onCompleted:
{
console.log("parent.data[0].objectName", head.data[0].objectName)
console.log("parent.data[1].objectName", head.data[1].objectName)
}
}
Output:
qml: parent.data[0].objectName ApplicationWindow
qml: parent.data[1].objectName
With Window
:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
id: head
visible: true
width: 640
height: 480
Rectangle{height:1; width: 1; objectName: "AA"}
Rectangle{height:1; width: 1; objectName: "BB"}
Component.onCompleted:
{
console.log("parent.data[0].objectName", head.data[0].objectName)
console.log("parent.data[1].objectName", head.data[1].objectName)
}
}
Output:
qml: parent.data[0].objectName AA
qml: parent.data[1].objectName BB
question from:
https://stackoverflow.com/questions/65952407/how-to-access-objectnames-of-objects-in-applicationwindow-of-qml 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…