Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Creating contact in Qt

From 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 (17 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 17 October 2012, at 22:19.
79 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.

×