2015-01-07 2 views
1

사용자 정의 listitem 구성 요소가있는 내 홈페이지에 listview가 있습니다. 홈페이지에서 액세스 할 수있는 Qsettings 변수에 값이 있지만 사용자 정의 listitem 구성 요소 내에서 동일한 변수에 액세스 할 수 없습니다. 홈페이지를로드 할 때 Qsetting 데이터 로그가 홈페이지의 CreateCompleted에 인쇄되지만 customlistitemhomepage의 onCreationCompleted에 오류가 표시됩니다. 다음은 내 홈페이지 구조와 customlistitem 홈페이지 구조에 대한 샘플 코드입니다.qml을 사용하여 블랙 베리 캐스케이드의 listview item 구성 요소 내에서 Qsettings 값에 액세스 할 수 없습니다.

Page { 
    Container { 
     layout: DockLayout { 
     } 
     ScrollView { 
      id: homePageScroll 
      Container { 
       layout: DockLayout { 
       } 
       ListView { 
        id: contactListView 
        dataModel: contactsData 
        preferredHeight: homePageScroll.listHeight 
        overlapTouchPolicy: OverlapTouchPolicy.Allow 
        listItemComponents: [ 
         ListItemComponent { 
          id: homeListComponent 
          type: "item" 
          CustomListItemHomePage { 
           id: listCell 
          } 
          //Some code 
         } 
        ] 
       } 
      } 
     } 

     onCreationCompleted: { 
       console.log("Clipboard value:"+_settings.getValueFor("clipBoard", "No Data")); //THIS PRINTS CORRECTLY 
     } 
    } 
} 

는 또한리스트 뷰에서 외부 함수를 호출하는 권리가 없습니다 CustomListItemHomePage.qml 내부

CustomListItemHomePage { 
    onCreationCompleted: { 
     console.log("Clipboard value:"+_settings.getValueFor("clipBoard", "No Data")); //THIS SHOWS ERROR CAN'T Find variable _settings 
    }        
} 

답변

0

listItemComponents를 동일한 기록했다.

ListView { 
    id: contactListView 
    dataModel: contactsData 
    preferredHeight: homePageScroll.listHeight 
    overlapTouchPolicy: OverlapTouchPolicy.Allow 
    listItemComponents: [ 
     ListItemComponent { 
      id: homeListComponent 
      type: "item" 
      CustomListItemHomePage { 
       id: listCell 
       // Now you are able to call getClipboardValue() from ListItemComponent like 
       // listCell.ListItem.view.getClipboardValue() 
      } 
      //Some code 
     } 
    ] 
    function getClipboardValue() { 
     return _settings.getValueFor("clipBoard", "No Data")); 
    } 
} 
+0

가 어떻게 CustomListItemHomePage이 반환 값을 액세스합니까 : 당신이 CustomListItemHomePage.qml에서 QSettings 함수를 호출 할 경우 같은, 당신은 할 수 있습니까? homepage.qml의 listview에서 CustomListItemHomePage.qml 안에 함수를 트리거하는 방법이 있습니까? – Gamerlegend

+0

아니, 그걸 어떻게 쓸 건데? – Ankur

관련 문제