Display SIM contacts using QML ContactModel
This article shows how to use QML ContactModel Element/Contacts QML Plugin to display SIM contacts on the screen. Note that contacts can also be accessed in C++, using the Qt Contacts API. Note also that the snippet shows use of the API within a Symbian Qt Components framework - the code should work similarly on MeeGo using the MeeGo Qt Quick Components.
Article Metadata
Tested with
SDK: Nokia Qt SDK 1.1.4
Devices(s): Nokia C6-01
Compatibility
Device(s): Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: NetworkServices ReadUserData WriteUserData
Article
Keywords: ContactModel
Created: Devnull
(13 Dec 2011)
Last edited: hamishwillee
(13 Jun 2012)
Preconditions
Qt SDK version 1.1.4 or later. Create a new Qt Quick application.
Project File (.pro file)
- Add the Qt Mobility project configuration option in the .pro file as shown below:
CONFIG += mobility
MOBILITY += contacts
- Here is the project (.pro) file part related to Symbian capabilities:
symbian {
TARGET.CAPABILITY = NetworkServices ReadUserData WriteUserData
}QML file
Here is the MainPage.qml:
import QtQuick 1.1
import com.nokia.symbian 1.1
import QtMobility.contacts 1.1
Page {
id: mainPage
Text {
id: title
text: "Contacts"
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 6
color: platformStyle.colorNormalLight
}
ListView {
id: mainList
anchors.left: parent.left
anchors.leftMargin: 3
anchors.right: parent.right
anchors.rightMargin: 3
anchors.top: title.bottom
anchors.bottom: parent.bottom
anchors.topMargin: 3
cacheBuffer: 100
clip: true
highlightFollowsCurrentItem: true
snapMode: ListView.SnapOneItem
model: contactModel.contacts
delegate: listDelegate
ContactModel {
id: contactModel
manager: "symbiansim" // "symbian" for other contact manager
autoUpdate :true
sortOrders:
SortOrder {
detail: ContactDetail.Name
field: Name.LastName
direction: Qt.AscendingOrder
}
}
Component {
id: listDelegate
ListItem {
id: contactItem
subItemIndicator: true
ListItemText {
id: nameItem
mode: contactItem.mode
role: "Title"
text: displayLabel
}
}
}
ScrollDecorator {
flickableItem: mainList
}
}
}


Vdharankar - meego port
Wondering what it will take to port this to meego, don't see anything specific though.
VishalVishal Dharankar 11:29, 14 December 2011 (EET)
Hamishwillee - Vdharankar ... Good question
The categories indicate it is generic Qt, but the ArticleMetaData indicates it has a devicecompatibility with Symbian. Looking at the code I expect that this is generic and would run on MeeGo too.
If this is the case I'd add ArticleMetaData |platform=Qt 4.7
and either remove devicecompatibility or change to "All Symbian and N9" (assuming that is true)hamishwillee 05:39, 15 December 2011 (EET)