如何在Qt中删除联系人
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot update - Fix metadata) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| Line 30: | Line 30: | ||
==Qt工程文件== | ==Qt工程文件== | ||
| − | <code cpp> | + | <code cpp-qt> |
CONFIG += mobility | CONFIG += mobility | ||
MOBILITY = contacts | MOBILITY = contacts | ||
</code> | </code> | ||
| − | <code cpp> | + | <code cpp-qt> |
symbian { | symbian { | ||
TARGET.CAPABILITY = ReadUserData WriteUserData | TARGET.CAPABILITY = ReadUserData WriteUserData | ||
| Line 43: | Line 43: | ||
==头文件== | ==头文件== | ||
| − | <code cpp> | + | <code cpp-qt> |
// QtMobility | // QtMobility | ||
#include <qcontactmanager.h> | #include <qcontactmanager.h> | ||
| Line 54: | Line 54: | ||
==源文件== | ==源文件== | ||
| − | <code cpp> | + | <code cpp-qt> |
// Create manager (Symbian backend) | // Create manager (Symbian backend) | ||
QContactManager contactManager("symbian"); | QContactManager contactManager("symbian"); | ||
Latest revision as of 04:19, 11 October 2012
文章信息
Contents |
概述
下列代码片段演示了如何使用Qt Mobility的联系人模块来删除联系人数据
Qt工程文件
CONFIG += mobility
MOBILITY = contacts
symbian {
TARGET.CAPABILITY = ReadUserData WriteUserData
}
头文件
// QtMobility
#include <qcontactmanager.h>
#include <qcontact.h>
#include <qcontactdetailfilter.h>
#include <qcontactphonenumber.h>
QTM_USE_NAMESPACE
源文件
// 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()));
}
}
}
后记
联系人成功删除

