Read all contacts from device phonebook using Qt Mobility API
Article Metadata
| ID | Creation date | 15th Mar 2010 | |
| Platform | S60 5th Edition | Tested on devices | Nokia N97 Mini |
| Category | Qt | Subcategory | Qt Mobility API |
| Keywords (APIs, classes, methods, functions): QContactManager, QContactDetail |
This article shows how to read all contacts from device PhoneBook using Qt Mobility API
Contents |
Project configuration file (.Pro file)
- Add the Qt Mobility project configuration option in the .Pro file as shown below
CONFIG += mobility
MOBILITY += contacts
Header File
#include <QContactManager>
/* All QtMobility api's are part of QtMobility namespace. */
using namespace QtMobility;
Source File
void phonebook_manager::readall()
{
QStringList availableManagers = QContactManager::availableManagers();
for(int managerIdx = 0; managerIdx < availableManagers.count(); managerIdx++) {
QContactManager *manager = new QContactManager(availableManagers.at(managerIdx));
if(manager) {
QList<QContactLocalId> contacts = manager->contacts();
for(int contactIdx =0; contactIdx < contacts.count(); contactIdx++) {
QContact contact = manager->contact(contacts.at(contactIdx));
QString label =contact.displayLabel(); // display label of contact
QList<QContactDetail> contactDetails = contact.details();
foreach (const QContactDetail& details, contactDetails) {
QList<QString> fieldKeys = details.values().keys();
foreach (const QString& key, fieldKeys) {
// key : give you the Field name
// details.value(key) : give you Field value
}
}
}
delete manager;
}
}
}
Classes
- QContactManager
- QContactDetail
Reference links
- Qt - cross-platform application and UI framework
- Qt Mobility API
- New Qt APIs Beta - Mobility Project
- SDK help
--skumar_rao 14:42, 16 March 2010 (UTC)


(no comments yet)