【发布时间】:2016-09-29 11:03:38
【问题描述】:
我的代码:
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
Column {
Row {
Repeater {
id: rectRepeater
model: 3
Rectangle {
width: 30
height: 30
color: "red"
radius: 10
}
}
}
Row {
Repeater {
model: 3
Text {
text: rectRepeater.itemAt(0).width;
}
}
}
}
}
我收到此错误消息:
TypeError: 无法读取 null 的属性“宽度”
我发现this post 说解决方案是像这样使用Component.onCompleted(只需在Text 对象中插入一个Component.onCompleted 处理程序):
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
Column {
Row {
Repeater {
id: rectRepeater
model: 3
Rectangle {
width: 30
height: 30
color: "red"
radius: 10
}
}
}
Row {
Repeater {
model: 3
Text {
Component.onCompleted: {
text: rectRepeater.itemAt(0).width;
}
}
}
}
}
}
但这失败并出现同样的错误。
有什么想法吗?
【问题讨论】: