I think this is correct. Try aliasing to properties level component. That I
think works.
This is unfortunately an unfortunate limitation.
________________________________
From: Krenar Qehaja <[email protected]>
To: qt-qml <[email protected]>
Sent: Wednesday, February 29, 2012 6:17 PM
Subject: [Qt-qml] Cannot access child elements within Component
Hi everyone,
I cannot seem to access the child elements within a Component.
I can access them through JavaScript though, if I create a function and call it
when one of the root elements gets loaded, but not after.
Below is a snippet of code which illustrates my point:
import QtQuick 1.0
Rectangle {
id: base
color: "transparent"
width: 500
height: 500
// this function will be used to get the height of 'items', it works fine
function getHeight(item1) {
console.log("items height using getHeigh function: "+item1.height)
}
// listview
ListView {
id: listView
width: parent.width; height: parent.height
spacing: 5
model: fruitModel
delegate: fruitDelegate
focus: true
Keys.onPressed: { // listen for any key
console.log("listView height: " + listView.height); // Try to get
'listView' Heigh, it works
console.log("items height: " + items.height); // Try to get
'items' height, this does not work.
// This error will
appear in the console: Can't find variable: items
// I should be able to
access the items.height from here, or access fruitDelegate children from here
// or try
with console.log("items height: " + getHeight(items));
}
}
ListModel { // Some list
id: fruitModel
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
}
Component { // Delegate
id: fruitDelegate
Row {
id: items
height: 15
spacing: 10
Text { text: name }
Text { text: '$' + cost }
Component.onCompleted: {
getHeight(items); // I can access the height property of
'items' when I pass the 'items' id to the getHeight function
}
}
}
}
When Component loads, it calls getHeight function and it works just fine. But
when you press any key, you'll see an error complaining about items.height.
So, I don't know if this is a bug or it was meant that way but I really do need
to access those child elements.
Cheers,
Krenar
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml