Repeater::itemAt access to non-Item properties
-
Hello.
I define Block element and I use it with repeter:
@
Grid {
id: answerGrid
...
Repeater {
id: rep
model: 3
Block {
}
@When I use itemAt function:
@rep.itemAt(i)@
It return a Item object. And I can't access to variable with I add to Block item.
Is there any simple way to access it?
-
Hello,
that's strange. I used this and I did not have any problems. (http://developer.qt.nokia.com/wiki/QML_Scrolling_Digits)
Can you show more code or if there are some errors in output?
-
I create sample project
main.cpp
@import QtQuick 1.1
import "Addons" as AddonsRectangle {
id: board
(color, width ...)
Grid {
id: answerGrid
(anchors)
columns: 6
rows: 6
spacing: 7Repeater { id: blocks model: 36 Addons.Block{ id: block } } }
}
@Addons/block.qml
@
import QtQuick 1.1Rectangle {
id: block
(width,height...)
Grid {
property int row: Math.floor(index/answerGrid.columns)
property int col: index-row*answerGrid.columns
id: cellGrid
(anchors)
columns: 3
rows: 2
spacing: 2
Repeater {
id :repro
model: 6
Rectangle {
id: cell
(width,height,color)Text{ id: num (anchors) text: index } MouseArea{ id: cellMouse anchors.fill: parent onClicked: { console.log(blocks.itemAt(0).cellGrid) blocks.itemAt(0).cellGrid.rows = 5 } } } } }
}
@Conslole.log returns undefined value.
Next line return
@Addons/Block.qml:40: TypeError: Result of expression blocks.itemAt(0).cellGrid' [undefined] is not an object.@ -
Hello,
blocks is id from main.qml and it is not visible in block.qml See "Component scope":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativescope.html#component-scope
-
Thanks for replay :) Still I don't really undestand what element's are visible and with are not. I was able to access board.width or answerGrid.columns from block.qml with propably shoudn't be possible.
I solved problem with access to the element using itemAt.
When I used @console.log(blocks.itemAt(0).repro)@ it return undefined, but when I add @property alias repro: repro@ to block.qml it return right object.