Creating contact in Qt
Jump to navigation
Jump to search
Qt project file[edit | edit source]
CONFIG += mobility
MOBILITY = contacts
symbian {
TARGET.CAPABILITY = ReadUserData WriteUserData
}
Header[edit | edit source]
// QtMobility
- include <qcontactmanager.h>
- include <qcontact.h>
- include <qcontactdetailfilter.h>
- include <qcontactphonenumber.h>
- include <qcontactname.h>
QTM_USE_NAMESPACE
Source[edit | edit 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[edit | edit source]
A new contact is created.