×
Namespaces

Variants
Actions
(Difference between revisions)

How to read and display contacts from phonebook using Qt Mobility

From Nokia Developer Wiki
Jump to: navigation, search
kamalakshan (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Qt]][[Category:Qt for Symbian]]
+
[[Category:Qt Mobility]]
{{CodeSnippet
+
{{ArticleMetaData
 
|id=...
 
|id=...
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
 
|devices= Nokia 5800 and Nokia N97.
 
|devices= Nokia 5800 and Nokia N97.
|category=Qt for Symbian
+
|category=Qt
 
|subcategory= Qt Mobility API
 
|subcategory= Qt Mobility API
 
|creationdate=March 29, 2010
 
|creationdate=March 29, 2010
 
|keywords= QContactManager, QContact, QContactLocalId
 
|keywords= QContactManager, QContact, QContactLocalId
 +
 +
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
 +
|author=[[User:Yashu]]
 
}}
 
}}
  
 
==Overview==
 
==Overview==
  
This code example shows how to read contacts from contact book (phonebook). User might need to read contacts programmatically by one or more reason, this code example shows how to use QtMobility Contacts APIs to read contacts from contact book.
+
{{Abstract|This article shows how to read contacts from contact book (phonebook).}} User might need to read contacts programmatically by one or more reason, this code example shows how to use [http://doc.qt.nokia.com/qtmobility-1.2/contacts.html QtMobility Contacts APIs] to read contacts from contact book.
  
This snippet requires ReadUserData, ReadDeviceData capabilities. Self-signing is not possible, a [[Developer certificate]] is needed to sign application for testing.
+
This snippet requires {{Icode|ReadUserData}}, {{Icode|ReadDeviceData}} capabilities. Self-signing is not possible, a [[Developer certificate]] is needed to sign application for testing.
  
 
==Prerequisite==
 
==Prerequisite==
Line 23: Line 31:
  
 
==Headers required==
 
==Headers required==
<code cpp>
+
<code cpp-qt>
 
  #include <qtcontacts.h>
 
  #include <qtcontacts.h>
 
</code>
 
</code>
  
 
== .pro file==
 
== .pro file==
Modify your .pro file as follows.
+
Modify your''' .pro''' file as follows.
  
<code cpp>
+
<code cpp-qt>
 
INCLUDEPATH += D:/QtMobility/src/contacts \
 
INCLUDEPATH += D:/QtMobility/src/contacts \
 
INCLUDEPATH += D:/QtMobility/src/contacts/filters \
 
INCLUDEPATH += D:/QtMobility/src/contacts/filters \
Line 45: Line 53:
  
 
==Header file==
 
==Header file==
<code cpp>
+
<code cpp-qt>
  
 
#ifndef DISPLAYCONTACTS_H
 
#ifndef DISPLAYCONTACTS_H
Line 79: Line 87:
  
 
==Source file==
 
==Source file==
<code cpp>
+
<code cpp-qt>
  
 
#include "DisplayContacts.h"
 
#include "DisplayContacts.h"
Line 155: Line 163:
 
* Working [[Media:QtDisplayContacts.zip|Code Example]] is available to download from here.
 
* Working [[Media:QtDisplayContacts.zip|Code Example]] is available to download from here.
  
[[Category:Code Examples]]
+
[[Category:Code Examples]][[Category:MeeGo Harmattan]] [[Category:Symbian]]

Latest revision as of 04:23, 11 October 2012

Article Metadata
Tested with
Devices(s): Nokia 5800 and Nokia N97.
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QContactManager, QContact, QContactLocalId
Created: Yashu (29 Mar 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

This article shows how to read contacts from contact book (phonebook). User might need to read contacts programmatically by one or more reason, this code example shows how to use QtMobility Contacts APIs to read contacts from contact book.

This snippet requires ReadUserData, ReadDeviceData capabilities. Self-signing is not possible, a Developer certificate is needed to sign application for testing.

[edit] Prerequisite


[edit] Headers required

 #include <qtcontacts.h>

[edit] .pro file

Modify your .pro file as follows.

INCLUDEPATH += D:/QtMobility/src/contacts \
INCLUDEPATH += D:/QtMobility/src/contacts/filters \
INCLUDEPATH += D:/QtMobility/src/contacts/requests \
INCLUDEPATH += D:/QtMobility/src/contacts/details
INCLUDEPATH += D:/QtMobility/src/global
 
CONFIG += mobility
MOBILITY = contacts
 
symbian::TARGET.CAPABILITY = ReadUserData \
ReadDeviceData

[edit] Header file

#ifndef DISPLAYCONTACTS_H
#define DISPLAYCONTACTS_H
 
#include <QtGui/QMainWindow>
#include "qtcontacts.h"
 
QTM_USE_NAMESPACE
 
class QScrollArea;
class QListWidget;
 
class DisplayContacts : public QMainWindow
{
Q_OBJECT
 
public:
DisplayContacts(QWidget *parent = 0);
~DisplayContacts();
 
private:
void fetchContcatsFromContactBook();
 
private:
QListWidget *listWidget;
QScrollArea *scrollArea;
};
 
#endif // DISPLAYCONTACTS_H

[edit] Source file

#include "DisplayContacts.h"
#include <QListWidget>
#include <QScrollArea>
 
DisplayContacts::DisplayContacts(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Display Contacts");
 
/* To show items in list view */
listWidget = new QListWidget();
listWidget->setObjectName(QString::fromUtf8("listWidget"));
 
QSize screenSize(size());
resize(screenSize);
QRect rect(0,0,screenSize.width(), screenSize.height());
listWidget->setGeometry(rect);
 
/* To make UI scrollable */
scrollArea = new QScrollArea();
 
/* scrollArea takes ownership of the listWidget, so no need to delete it */
scrollArea->setWidget(listWidget);
scrollArea->setAlignment(Qt::AlignLeft);
scrollArea->setWidgetResizable(true);
 
/* QMainWindow takes ownership of the scrollArea, so no need to delete it */
setCentralWidget(scrollArea);
 
fetchContcatsFromContactBook();
}
 
DisplayContacts::~DisplayContacts()
{
 
}
 
void DisplayContacts::fetchContcatsFromContactBook()
{
/* read contact from "symbian" contact manager */
QContactManager *contactManager = new QContactManager("symbian");
 
/* You can also read contact from selected contact manager by selecting
* appropriate contact manager from available contact managers.
 
*QStringList availableManagers = QContactManager::availableManagers();
*iterate througn available manager and select appropriate one.
*contactManager = new QContactManager(availableManagers.at(2));
*/

 
/* get list of all contacts */
QList<QContactLocalId> contactIds = contactManager->contactIds();
QContact currContact;
 
/* appens it to list widget to display on screen*/
foreach (const QContactLocalId& id, contactIds)
{
currContact = contactManager->contact(id);
QString nameAndNumber(currContact.displayLabel() + ": " + currContact.detail(QContactPhoneNumber::DefinitionName).value(QContactPhoneNumber::FieldNumber));
listWidget->addItem(nameAndNumber);
}
}

[edit] Postconditions

The code snippet is expected to read and display contacts from symbian contact manager.

QtDisplayContacts.jpg

[edit] Download Code Example

This page was last modified on 11 October 2012, at 04:23.
90 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×