[SailfishDevel] QT Contacts Filter on Sailfish

christopher.lamb at thurweb.ch christopher.lamb at thurweb.ch
Sat Nov 30 20:01:20 UTC 2013


Hi All

I am playing around with QtContacts 5.0 on Sailfish (still on the Emulator ..)

I am able to add, display and sort contacts. So far so good. My code  
is at the bottom of this mail

However things go pear-shaped when I try and filter the contacts: I  
get the error:
file:///usr/share/ContactsDemo/qml/pages/FirstPage.qml:62: Unable to  
assign int to [unknown property type]

This refers to the detail: ContactDetail.Name of the Filter, even  
though it was able to use an identical property to sort.

Having delved into the source of QDeclarativeContactSortOrder and  
QDeclarativeContactDetailFilter, I see that the first declares detail  
to be of type int, but the second declares detail to be  
QDeclarativeContactDetail::DetailType


class QDeclarativeContactSortOrder :public QObject, public QQmlParserStatus
{
     Q_OBJECT
     Q_PROPERTY(int detail READ detail WRITE setDetail NOTIFY sortOrderChanged)

class QDeclarativeContactDetailFilter : public  
QDeclarativeContactFilter, public QQmlParserStatus
{
     Q_OBJECT
     Q_PROPERTY(QDeclarativeContactDetail::DetailType detail READ  
detail WRITE setDetail NOTIFY valueChanged())

However I have got no further in figuring out what I am doing wrong /  
what is going wrong.

Something very similar to the code below works on Harmattan.

Any ideas?

Thanks

Chris


//Start FirstPage.qml
import QtQuick 2.0
import Sailfish.Silica 1.0
import QtContacts 5.0
Page {
     id: page
     ContactModel {
         id: contactsModel
         manager: "memory"
         Component.onCompleted: {
             //contactsModel.importContacts(Qt.resolvedUrl("example.vcf"))
             page.insertContact("Mary", "Curie", "+41791234545")
             page.insertContact("Empress", "of Blandings", "+41791234546")
             page.insertContact("Big", "Lebowski", "+41791234546")
             page.insertContact("Clive", "Sinclair", "+41791234546")
             page.insertContact("Winston", "Churchill", "+41791234547")
         }
         sortOrders: [
             SortOrder {
                 detail: ContactDetail.Name
                 field: Name.FirstName
                 direction: Qt.AscendingOrder
             }
         ]
         filter: detailFilter1
     }
     DetailFilter {
         id: detailFilter1
         detail: ContactDetail.Name
         field: Name.FirstName
         value: "M"
         matchFlags: Filter.MatchContains
     }
     ListView {
          id:  contactList
          anchors.fill: parent
          model: contactsModel
          delegate:contactDelegate
          clip: true
          onCountChanged: {
              contactList.currentIndex = -1;
              console.log("Contacts Count: contactList.count: " + count);
          }
      }
     Component {
         id: contactDelegate
         PhoneContactsDelegate {
         }
     }
     function insertContact(firstName, lastName, phoneNumber) {
         // read in values from the input fields
         var displaylabel = firstName.trim() + " " + lastName.trim()
         var values = [firstName,
                       lastName,
                       displaylabel,
                       phoneNumber]
         var newContact = Qt.createQmlObject("import QtContacts 5.0;  
Contact{ }", page)
         setDetailValues(newContact, values)
         newContact.save()
         contactsModel.saveContact(newContact)
     }
     function setDetailValues(c, values) {
         c.name.firstName = values[0]
         c.name.lastName = values[1]
         c.displayLabel.label = values[2]
         c.phoneNumber.number = values[3]
     }
}
//End FirstPage.qml
//Start PhoneContactsDelegate.qml
import QtQuick 2.0
Item {
     id: backGroundRect
     width: parent.width
     height: 80
     Text {
         id: nameText
         anchors {left: parent.left; leftMargin: 10; right:  
parent.right; rightMargin: 10; top: parent.top}
         font.pointSize: 30
         font.weight: Font.DemiBold
         text: model.contact.displayLabel.label.trim();
     }
     Text {
         id: numberText
         anchors {left: parent.left; leftMargin: 10; right:  
parent.right; rightMargin: 10; top: nameText.bottom}
         font.pointSize: 20
         font.weight: Font.Light
         text: model.contact.phoneNumber.number // + ", " +  
model.contact.contactId
     }
}
//End PhoneContactsDelegate.qml



More information about the Devel mailing list