×
Namespaces

Variants
Actions
(Difference between revisions)

如何在Qt中删除联系人

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Add link to original article)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update of Template:ArticleMetaData)
Line 13: Line 13:
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|language=Lang-Chinese
 
|language=Lang-Chinese
|translated-by= <!-- [[User: XXXXX]] -->
+
|translated-by=[[User:Hoolee]]
|translated-from-title=<!-- Title only -->
+
|translated-from-title=CS001623 - Removing contact in Qt
|translated-from-id= <!-- Id of translated revision -->
+
|translated-from-id=74922 <!-- automated guess -->
 
|review-by=<!-- After re-review: [[User:username]] -->
 
|review-by=<!-- After re-review: [[User:username]] -->
 
|review-timestamp=<!-- After re-review: YYYYMMDD -->
 
|review-timestamp=<!-- After re-review: YYYYMMDD -->
Line 21: Line 21:
 
|update-timestamp=<!-- After significant update: YYYYMMDD -->
 
|update-timestamp=<!-- After significant update: YYYYMMDD -->
 
|creationdate=20100528
 
|creationdate=20100528
|author=[[User:Hoolee]]
+
|author=[[User:Tepaa]]
 
}}
 
}}
  
Original: [[CS001623 - Removing contact in Qt]]
 
  
 
==概述==
 
==概述==
Line 98: Line 97:
 
* [[Setting_up_Qt_Mobility]]
 
* [[Setting_up_Qt_Mobility]]
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
 +
<!-- Translation --> [[en:CS001623 - Removing contact in Qt]]

Revision as of 02:04, 19 December 2011

Article Metadata

兼容于
平台:
Symbian

文章
翻译:
hoolee
最后由 hamishwillee 在 19 Dec 2011 编辑


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

后记

联系人成功删除

相关参考

213 page views in the last 30 days.
×