×
Namespaces

Variants
Actions
Revision as of 01:19, 18 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Creating contact in Qt

From Nokia Developer Wiki
Jump to: navigation, search

This code snippet demonstrates how to create a new contact 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: QContactManager, QContact
Created: tepaa (25 May 2010)
Last edited: hamishwillee (18 Oct 2012)

Contents

Qt project file

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

Header

// QtMobility
#include <qcontactmanager.h>
#include <qcontact.h>
#include <qcontactdetailfilter.h>
#include <qcontactphonenumber.h>
#include <qcontactname.h>
QTM_USE_NAMESPACE

Source

// Create manager (Symbian backend)
QContactManager contactManager("symbian");
 
// Create a new empty contact
QContact contact;
 
// Set firstname and lastname
QContactName name;
name.setFirstName("Steven");
name.setLastName("Segal");
contact.saveDetail(&name);
 
// Set number
QContactPhoneNumber number;
number.setNumber("1234567890");
contact.saveDetail(&number);
 
// Save the contact
if (!contactManager.saveContact(&contact)) {
QMessageBox::information(this, "Failed!",
QString("Failed to save contact!\n(error code %1)").arg(contactManager.error()));
}

Postconditions

A new contact is created.

See also

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