×
Namespaces

Variants
Actions
(Difference between revisions)

Removing contact in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Abstract. Tidy wiki text)
 
Line 1: Line 1:
 +
[[Category:Qt]][[Category:PIM]][[Category:Qt Mobility]][[Category:Symbian]][[Category:MeeGo Harmattan]][[Category:S60 5th Edition]][[Category:Code Snippet]]
 +
{{Abstract|This code snippet demonstrates how to remove contact data using the Qt Mobility Contacts module.}}
 +
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
Line 21: Line 24:
 
|author= [[User:Tepaa]]
 
|author= [[User:Tepaa]]
 
<!-- The following are not in current metadata -->
 
<!-- The following are not in current metadata -->
|subcategory= Qt Mobility
 
 
|id= CS001623
 
|id= CS001623
 
}}
 
}}
 
==Overview==
 
 
This code snippet demonstrates how to remove contact data in Qt using the Contacts module of Qt Mobility.
 
  
 
==Qt project file==
 
==Qt project file==
Line 98: Line 96:
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
  
[[Category:Qt]][[Category:Qt Mobility]][[Category:Code Snippet]][[Category:Code Snippet]][[Category:MeeGo Harmattan]] [[Category:Symbian]]
+
 
<!-- Translation --> [[zh-hans:如何在Qt中删除联系人]]
 
<!-- Translation --> [[zh-hans:如何在Qt中删除联系人]]

Latest revision as of 01:18, 18 October 2012

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

Contents

[edit] Qt project file

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

[edit] Header

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

[edit] 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()));
}
}
}

[edit] Postconditions

A contact is removed.

[edit] See also

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