Removing 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>
QTM_USE_NAMESPACE
Source[edit | 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()));
}
}
}
Postconditions[edit | edit source]
A contact is removed.
See also[edit | edit source]
zh-hans:如何在Qt中删除联系人