2014-10-31 2 views
1

주요 목표 : QML 파일 (예 : file_1.qml)에 정의 된 항목에 의해 설정되고 다른 QML 파일에 정의 된 다른 항목에 의해 런타임에 액세스되는 컨텍스트 속성을 갖습니다. file_2.qml).QML 코드에서 컨텍스트 속성을 변경하십시오.

질문 : file_1.qml에 새 컨텍스트 속성을 설정하고 file_2.qml에서이 속성을 읽을 수 있습니까?

(편집)

예를 들어, 내가 file_1.qml에 file_2.qml에서 값을 사용해야합니다 :

file_1.qml :

(...) 
UiController.but_generate__onClicked(
    getContextProperty("sbx_money_quantity_value"), 
    cal_daysoff.visibleMonth) 
(...) 

file_2.qml :

(...) 
SpinBox { 
     id: sbx_money_quantity 
     objectName: "sbx_money_quantity" 
     Layout.fillWidth: true 
     minimumValue: 0 
     maximumValue: 100000 
     value: 20000 


     onChanged: setContextProperty("sbx_money_quantity_value",value) 
    } 
(...) 

고마워요!

+0

당신이 보여줄 수있는 샘플 코드를 설명 : 예를 들어,문제? – folibis

+0

예제를 추가했습니다. 감사 – pedromateo

답변

1

범위 제한으로 인해 다른 파일의 항목에 액세스 할 수 없습니다. 따라서 프록시 루트 객체가 필요하거나 일부 전역 단일 객체가되거나 한 객체에 대한 참조를 다른 객체로 전달할 수 있습니다.

File1.qml

Item { 
    property someValue: 1 
} 

File2.qml

Item { 
    property variant ref: null 
    onChanged: ref.someValue = 2; 
} 

main.qml

File1 { 
    item: file1 
} 
File2 { 
    item: file2 
    ref: file1 
} 
관련 문제