我有一个 MapPolyline 列表,我尝试将动态添加的对象保存到此列表中。很好,但是当我尝试获取列表中的对象时,它不起作用。它说TypeError: Cannot read property of undefined
这是我的代码
property list<MapPolyline> lines
var component;
var sprite;
component = Qt.createComponent("lineStringComponent.qml");
sprite = component.createObject(window,{"id": "button1"});
sprite.addCoordinate(QtPositioning.coordinate(currentgcppoint.lat, currentgcppoint.lon));
sprite.addCoordinate(gcppoint);
map.addMapItem(sprite)
lines.push(sprite)
gcps.push(currentgcppoint)
console.log("Added:", lines[1])
console.log("width:", lines[1].line.width)
这是lineStringComponent.qml
import QtQuick 2.2
import QtLocation 5.6
import QtPositioning 5.6
MapPolyline {
id:polyline
line.width: 3
line.color: Qt.rgba(Math.random(),Math.random(),Math.random())
}
控制台输出为:
Added: undefined
TypeError: Cannot read property 'line' of undefined
尝试创建新对象时似乎有延迟。我们如何克服这种延迟?