[英]How to get value from a property in Qml from another Qml?
我知道這個問題被問過很多次,但是沒有答案可以幫助我。 我有兩個QML文件。 第一個Qml文件中有一個地圖,當我在地圖上按時,它將打開一個包含以下代碼的窗口:
MouseArea{
id: mouseArea
property var positionRoot: map.toCoordinate(Qt.point(mouseX, mouseY))
anchors.fill: parent
onClicked: {
var component = Qt.createComponent("addAttribute.qml")
if (component.status === Component.Ready) {
var dialog = component.createObject(parent,{popupType: 1})
dialog.show()
}
}
}
該窗口具有label
, textfield
和button
。 我想要的是獲取在第一個QML文件中創建的property
(positionRoot)的值。 我怎么可能呢?
多虧@folibis,它才有效。 這是需要添加的代碼。
MouseArea{
id: mouseArea
property var positionRoot: map.toCoordinate(Qt.point(mouseX, mouseY))
anchors.fill: parent
onClicked: {
var component = Qt.createComponent("addAttribute.qml")
if (component.status === Component.Ready) {
var dialog = component.createObject(parent,{popupType: 1})
dialog.sqlPosition = positionRoot
dialog.show()
}
}
}
在第二個窗口中,我僅創建一個名為sqlPosition的新屬性。 例如:
Window {
id: secondWindow
property var sqlPosition
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.