×
Namespaces

Variants
Actions
(Difference between revisions)

Reading contact data in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Abstract. Improve categories)
 
Line 1: Line 1:
 +
[[Category:Qt]][[Category:PIM]][[Category:Symbian]][[Category:MeeGo Harmattan]][[Category:Code Snippet]][[Category:S60 5th Edition]][[Category:Qt Mobility]]
 +
{{Abstract|This code snippet demonstrates how to read contact data using the Qt Mobility Contacts module. }}
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
Line 21: Line 23:
 
|author= [[User:Tepaa]]
 
|author= [[User:Tepaa]]
 
<!-- The following are not in current metadata -->
 
<!-- The following are not in current metadata -->
|subcategory= Qt Mobility
 
 
|id= CS001622
 
|id= CS001622
 
}}
 
}}
  
 
==Overview==
 
==Overview==
 
This code snippet demonstrates how to read contact data in Qt using the Contacts module of Qt Mobility.
 
  
 
Contact data can be read through [http://doc.qt.nokia.com/qtmobility-1.0/qcontactdetail.html QContactDetail] and all of its subclasses.
 
Contact data can be read through [http://doc.qt.nokia.com/qtmobility-1.0/qcontactdetail.html QContactDetail] and all of its subclasses.
Line 111: Line 110:
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
 
* http://doc.qt.nokia.com/qtmobility-1.0/qcontactdetail.html
 
* http://doc.qt.nokia.com/qtmobility-1.0/qcontactdetail.html
 
 
[[Category:Qt]][[Category:Qt Mobility]][[Category:Code Snippet]][[Category:Code Snippet]][[Category:MeeGo Harmattan]] [[Category:Symbian]]
 

Latest revision as of 01:12, 18 October 2012

This code snippet demonstrates how to read contact data using the Qt Mobility Contacts module.

Article Metadata
Tested with
Devices(s): Nokia N97
Compatibility
Platform(s): S60 5th Edition
Symbian
S60 5th Edition
Article
Keywords: QContactDetailDefinition, QContactDisplayLabel, QContactDetail, QContactManager, QContact
Created: tepaa (25 May 2010)
Last edited: hamishwillee (18 Oct 2012)

Contents

[edit] Overview

Contact data can be read through QContactDetail and all of its subclasses.

[edit] Qt project file

CONFIG += mobility
MOBILITY = contacts
symbian {
TARGET.CAPABILITY = ReadUserData WriteUserData
}

[edit] Header

// QtMobility
#include <qcontactmanager.h>
#include <qcontact.h>
#include <qcontactdetailfilter.h>
#include <qcontactphonenumber.h>
#include <qcontactemailaddress.h>
QTM_USE_NAMESPACE
 
private:
QPointer<QContactManager> m_contactManager;

[edit] Source

1) Create manager first, see more in Finding contact manager in Qt.

// Create manager (Symbian backend)
m_contactManager = new QContactManager("symbian");

2) Search one contact, see more in Searching contact in Qt.

QContact contact = searchContact("1234567890");

3) Reading contact detail data

3.1) Data can be read using QContactDetail subclasses (for instance, QContactDisplayLabel and QContactEmailAddress).

QContactDisplayLabel displayLabel = contact.detail(QContactDisplayLabel::DefinitionName);
QMessageBox::information(this,"QContactDisplayLabel",displayLabel.label());
 
QContactEmailAddress email = contact.detail(QContactEmailAddress::DefinitionName);
QMessageBox::information(this,"QContactEmailAddress",email.emailAddress());

3.2) Looping through all QContactDetail of QContact

QString s;
QList<QContactDetail> allDetails = contact.details();
foreach (const QContactDetail& detail, allDetails) {
s += detail.definitionName();
s += " : ";
QVariantMap fieldValues = detail.variantValues();
QStringList keys = fieldValues.keys();
foreach (const QString& key, keys) {
s += key + "=" + detail.value(key) + ";";
}
s += "\n";
}
 
// Show all QContactDetail data to the user
QMessageBox::information(this,"QContactDetail",s);


[edit] Postconditions

QContactDetail data is searched and shown to the user.

[edit] See also

This page was last modified on 18 October 2012, at 01:12.
66 page views in the last 30 days.
×