2016-07-06 3 views
0

그의 모델이 U1db에서 오는 ListView가 있습니다. 쿼리 U1db와의 읽기 및 저장 작업은 작동하지만 새 항목을 삽입 할 때 ListView 모델을 업데이트해야합니다. 삽입 된 마지막 컨텐츠를 표시하는 데이터베이스 (예 : 동일한 쿼리를 실행해야 함). 나는 또한 ListView 및 UbuntuListView` 시도했지만이 문제를 해결할 수 없습니다. 난 '당겨'하면 목록은 내가 오류를 새로 고침 : 나는 SDK의 문서에서 보았다하지만 난 어떤 유용한 예제를 발견하지 않았습니다우분투 qml ListView 모델 새로 고침 U1Db 쿼리

Property 'update' of object U1db::Query(0xe097e0) is not a function

. 어떤 제안을 주셔서 감사합니다! 여기에 조각

는 (좀 detils를 생략 한) :

import QtQuick 2.2 
    import Ubuntu.Components 1.3 
    import Ubuntu.Components.Popups 1.3 

    import Ubuntu.Components.ListItems 1.3 as ListItem //test 

    import U1db 1.0 as U1db 

//the delegate component used by the ListView 
Component { 
      id: peopleListDelegate 

      Item { 
       id: personItem     

       //draw a rectangle aroun the content to display 
       Rectangle { 
       //content omitted 
       } 

       // This mouse region covers the entire delegate 
       MouseArea { 
        //content omitted    
       } 

       Row { 
        id: topLayout      
        //display some content to be shown inside the Rectangle 
       } 
      } 
     } 


//the listView that show the DB Query result 
     ListView { 

         id: listView 
         anchors.fill: parent 
         model : allPeopleQuery 
         delegate: peopleListDelegate 

         highlight: highlightComponent     
         focus: true 

         Component{ 
          id: listHeader 

          Item { 
           width: parent.width 
           height: units.gu(10) 

           Text{ 
            anchors.bottom: parent.bottom 
            anchors.horizontalCenter: parent.horizontalCenter 
            text: i18n.tr("<b> Total people found: </b>") + listView.count 
           } 
          } 
         } 

         header: listHeader 

         PullToRefresh {        
           refreshing: listView.model.status === ListModel.Loading 
           onRefresh: listView.model.update() // HERE THE PROBLEM, (also using reload() doesn't work) 
          } 
        } 

     U1db.Database { 
       id: mypeopleDb 
       ..... 
      } 

      U1db.Index{ 
       database: mypeopleDb 
       id: all_field_index 
       expression: ....... 
      } 


      U1db.Query { 
       id: allPeopleQuery 
       index: all_field_index 
       query: ["*", "*"] 
      } 

답변

0

시도 몇 일 후에 내가이 "수정"을하는 방법을 발견했다. U1db에 "model"이라는 쿼리가있는 ListView에는 모델 자동 새로 고침 기능이 있습니다 (예 : DB에 항목을 추가/제거하고 쿼리의 resultSet을 변경하면 모델이 업데이트 됨). 그러나, AdaptiveLayout 내부에 위의 코드를 사용하고 같은 문으로 페이지 사이 전환 :

myAdaptiveLayout.addPageToNextColumn(aPage,Qt.resolvedUrl('AddPerson.qml')) 

모델의 자동 새로 고침이 작동하지 않습니다!

'AddPerson.qml'파일의 페이지 코드를 AdaptiveLayout이 정의 된 동일한 qml 파일에 포함시키는 경우 ListView 모델 자동 새로 고침이 작동합니다.

참고 :이 해결책이 해결 방법인지 또는 qml 버그인지는 잘 모릅니다.