Creating contact in Qt
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
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.

