×
Namespaces

Variants
Actions
Revision as of 19:11, 25 May 2010 by jimgilmour1 (Talk | contribs)

Removing contact in Qt

From Nokia Developer Wiki
Jump to: navigation, search


Article Metadata
Tested with
Devices(s): Nokia N97
Compatibility
Platform(s): S60 5th Edition
Symbian
S60 5th Edition
Article
Keywords: QContactDetailFilter, QContactManager, QContact
Created: (25 May 2010)
Last edited: jimgilmour1 (25 May 2010)

Overview

This code snippet demonstrates how to remove contact data in Qt using Contacts module of Qt Mobility.

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>
QTM_USE_NAMESPACE

Source

// Create manager (Symbian backend)
QContactManager contactManager("symbian");
 
// Search contact by phone number
QContact contact;
// Filter for search
QContactDetailFilter phoneFilter;
phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName,
QContactPhoneNumber::SubTypeMobile);
phoneFilter.setValue("0503654295");
phoneFilter.setMatchFlags(QContactFilter::MatchPhoneNumber);
 
// Find contacts
QList<QContact> matchingContacts = contactManager.contacts(phoneFilter);
if (matchingContacts.size() != 0) {
contact = matchingContacts.at(0);
}
 
// Remove contact
if (!contact.isEmpty()) {
if (QMessageBox::Yes == QMessageBox::question(this,"Contact",
QString("Do you want to remove contact: %1").arg(contact.displayLabel()),
QMessageBox::Yes|QMessageBox::No)) {
 
bool ret = contactManager.removeContact(contact.localId());
if (!ret) {
QMessageBox::information(this, "Failed!",
QString("Failed to remove contact!\n(error code %1)")
.arg(contactManager.error()));
}
}
}

Postconditions

Contact removed.

See also

59 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.

×