0

I have a ListView with his model coming from a U1db.Query The reading and saving operations from/to U1db works, but i need to update the ListView model when a new item is inserted in the database to diplay the last content inserted (ie: i need to excute the same query). I have also tried with ListView and UbuntuListView` but i can't solve this issue. When i 'pull' the List to refresh it i get the error:

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

I have looked at the sdk doc but i haven't found any useful examples. Thanks for any suggestions !

Here the snippet (i have omitted some 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: ["*", "*"]
           }

1 Answers1

0

After some days of attempts i have found how to "fix" this. A ListView with a query fom U1db as "model" have a builtin automatic refresh of the model (eg: if you add/remove items in the DB and the resultSet of the query changes the model will be updated). But, using the code above inside an AdaptiveLayout, and switching between pages with statement like:

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

the automatic refresh of the model doesn't work !

If you include the page code from the file 'AddPerson.qml' inside the same qml file where is defined the AdaptiveLayout the ListView model auto refresh works !!!

NOTE: I don't know if this solution is a workaround or is a qml bug.