2017-10-24 9 views
0

MapPolyline의 목록이 있는데 동적으로 추가 된 개체를이 목록에 저장하려고합니다. 잘 작동하지만 목록에서 객체를 가져 오려고하면 작동하지 않습니다. 내 코드 여기목록에있는 요소의 QML 액세스 속성

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) 

이입니다 여기에 TypeError: Cannot read property of undefined을 말한다 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 

. 이 지연을 어떻게 극복 할 수 있습니까? 난 당신의 코드를 읽을 경우 line[1]lines의 두 번째 요소를 검색하려고보다

답변

1

제대로 만 lines1 요소를 추가합니다. 이것은 분명히 undefined입니다.

lines의 첫 번째 요소 인 line[0]에 액세스 해보세요.
JS 배열의 색인은 0으로 시작합니다 (대부분의 언어에서와 같이). 당신은 당신이 와우 (sprite.addCoordinate(...))

+0

을 속성 중 하나를 변경하지 수있는 것보다

는, 객체 생성과 지연이 될 경우 덕분에 매우 내가 감사를 매우주의하지 않았다 나의 명백한 실수였다 많은 –