本文整理汇总了C++中QContactEmailAddress::setEmailAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ QContactEmailAddress::setEmailAddress方法的具体用法?C++ QContactEmailAddress::setEmailAddress怎么用?C++ QContactEmailAddress::setEmailAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QContactEmailAddress
的用法示例。
在下文中一共展示了QContactEmailAddress::setEmailAddress方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: textChanged
void CntEmailEditorViewItem::textChanged( QString aText )
{
HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
QContactEmailAddress address = item->detail();
address.setEmailAddress( aText );
item->setDetail( address );
}
示例2: emailSupport
void TestCntActions::emailSupport()
{
QContact contact;
QContactEmailAddress email;
email.setEmailAddress("[email protected]");
contact.saveDetail(&email);
m_manager->saveContact(&contact);
//one number exist in contact
QList<QContactEmailAddress> emailList = contact.details<QContactEmailAddress>();
QVERIFY(emailList.count() == 1);
//one action expected
QList<QContactActionDescriptor> actionDescriptors = contact.availableActions();
QStringList actions;
for (int i = 0;i < actionDescriptors.count();i++)
{
QString action = actionDescriptors.at(i).actionName();
actions << action;
}
QVERIFY(actions.count() == 1);
QVERIFY(actions.contains("email", Qt::CaseInsensitive));
//pick first number for the actions
QContactEmailAddress emailAddress = contact.detail<QContactEmailAddress>();
//Test Email action
QList<QContactActionDescriptor> emailActionDescriptors = QContactAction::actionDescriptors("email", "symbian");
QVERIFY(emailActionDescriptors.count() == 1);
QContactAction *emailAction = QContactAction::action(emailActionDescriptors.at(0));
QVERIFY(emailAction != 0);
QVERIFY(emailAction->isDetailSupported(emailList.at(0)) == true);
QList<QContactDetail> supportedDetails = emailAction->supportedDetails(contact);
QVERIFY(supportedDetails.count() != 0);
QVariantMap variantMap = emailAction->metaData();
QVERIFY(variantMap.count() == 0);
variantMap = emailAction->results();
QVERIFY(variantMap.count() == 0);
QSignalSpy spyEmailAction(emailAction, SIGNAL(stateChanged(QContactAction::State)));
emailAction->invokeAction(contact, emailAddress);
emailAction->invokeAction(contact);
QTRY_COMPARE(spyEmailAction.count(), 2); // make sure the signal was emitted exactly one time
delete emailAction;
}
示例3: updateContact
void MainWindow::updateContact()
{
const QString& name = m_nameEdit->text();
const QString& phone = m_phoneEdit->text();
const QString& email = m_emailEdit->text();
if (!name.isEmpty()) {
QContactName detail = m_contact.detail<QContactName>();
detail.setFirstName(name);
m_contact.saveDetail(&detail);
}
if (!phone.isEmpty()) {
QContactPhoneNumber detail = m_contact.detail<QContactPhoneNumber>();
detail.setNumber(phone);
m_contact.saveDetail(&detail);
}
if (!email.isEmpty()) {
QContactEmailAddress detail = m_contact.detail<QContactEmailAddress>();
detail.setEmailAddress(email);
m_contact.saveDetail(&detail);
}
}
示例4: bufPtr
//.........这里部分代码省略.........
m_engine.setReadOnlyAccessConstraint(&lastNumber);
currentContact.saveDetail(&lastNumber);
}
}
}
// We have rearched to the end of the number,
// invalidate additional number flag.
isAdditionalNumber = false;
break;
}
case RMobilePhoneBookStore::ETagPBText:
{
if (pbBuffer->GetValue(bufPtr) == KErrNone) {
if (isAdditionalNumber) {
// For additional number bufPtr contains number alpha string,
// this is ignored currently
}
else {
// Contact name otherwise
QContactName name;
QString nameString = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
name.setCustomLabel(nameString);
if (m_storeInfo.m_readOnlyAccess)
m_engine.setReadOnlyAccessConstraint(&name);
currentContact.saveDetail(&name);
QContactManager::Error error(QContactManager::NoError);
m_engine.setContactDisplayLabel(¤tContact, m_engine.synthesizedDisplayLabel(currentContact, &error));
}
}
break;
}
case RMobilePhoneBookStore::ETagPBSecondName:
{
if (pbBuffer->GetValue(bufPtr) == KErrNone) {
QContactNickname nickName;
QString name = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
nickName.setNickname(name);
if (m_storeInfo.m_readOnlyAccess)
m_engine.setReadOnlyAccessConstraint(&nickName);
currentContact.saveDetail(&nickName);
}
break;
}
case RMobilePhoneBookStore::ETagPBNumber:
{
if (pbBuffer->GetValue(bufPtr) == KErrNone) {
QContactPhoneNumber phoneNumber;
QString number = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
phoneNumber.setNumber(number);
if (m_storeInfo.m_readOnlyAccess)
m_engine.setReadOnlyAccessConstraint(&phoneNumber);
currentContact.saveDetail(&phoneNumber);
}
break;
}
case RMobilePhoneBookStore::ETagPBAnrStart:
{
// This tag should precede every additional number entry
isAdditionalNumber = true;
break;
}
case RMobilePhoneBookStore::ETagPBEmailAddress:
{
if (pbBuffer->GetValue(bufPtr) == KErrNone) {
QContactEmailAddress email;
QString emailAddress = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
email.setEmailAddress(emailAddress);
if (m_storeInfo.m_readOnlyAccess)
m_engine.setReadOnlyAccessConstraint(&email);
currentContact.saveDetail(&email);
}
break;
}
case RMobilePhoneBookStore::ETagPBNewEntry:
{
// This signals the end of the entry and is a special case
// which will be handled below.
break;
}
default:
{
// An unsupported field type - just skip this value
pbBuffer->SkipValue(dataType);
break;
}
} //switch
// save contact to the array of contact to be returned if the whole entry was extracted
if ((tagValue == RMobilePhoneBookStore::ETagPBNewEntry && currentContact.localId() > 0) ||
(pbBuffer->RemainingReadLength() == 0 && currentContact.localId() > 0)) {
fetchedContacts.append(currentContact);
//clear current contact
currentContact.clearDetails();
QScopedPointer<QContactId> contactId(new QContactId());
contactId->setLocalId(0);
contactId->setManagerUri(QString());
currentContact.setId(*contactId);
}
} //while
示例5: generateContact
QContact generateContact(const QString &syncTarget = QString(QLatin1String("local")), bool possiblyAggregate = false)
{
static const QStringList firstNames(generateFirstNamesList());
static const QStringList middleNames(generateMiddleNamesList());
static const QStringList lastNames(generateLastNamesList());
static const QStringList nonOverlappingFirstNames(generateNonOverlappingFirstNamesList());
static const QStringList nonOverlappingLastNames(generateNonOverlappingLastNamesList());
static const QStringList phoneNumbers(generatePhoneNumbersList());
static const QStringList emailProviders(generateEmailProvidersList());
static const QStringList avatars(generateAvatarsList());
static const QStringList hobbies(generateHobbiesList());
// we randomly determine whether to generate various details
// to ensure that we have heterogeneous contacts in the db.
QContact retn;
int random = qrand();
bool preventAggregate = (syncTarget != QLatin1String("local") && !possiblyAggregate);
// We always have a sync target.
QContactSyncTarget synctarget;
synctarget.setSyncTarget(syncTarget);
retn.saveDetail(&synctarget);
// We always have a name. Select an overlapping name if the sync target
// is something other than "local" and possiblyAggregate is true.
QContactName name;
name.setFirstName(preventAggregate ?
nonOverlappingFirstNames.at(random % nonOverlappingFirstNames.size()) :
firstNames.at(random % firstNames.size()));
name.setLastName(preventAggregate ?
nonOverlappingLastNames.at(random % nonOverlappingLastNames.size()) :
lastNames.at(random % lastNames.size()));
if ((random % 6) == 0) name.setMiddleName(middleNames.at(random % middleNames.size()));
if ((random % 17) == 0) name.setPrefix(QLatin1String("Dr."));
retn.saveDetail(&name);
// Favorite
if ((random % 31) == 0) {
QContactFavorite fav;
fav.setFavorite(true);
retn.saveDetail(&fav);
}
// Phone number
if ((random % 3) == 0) {
QContactPhoneNumber phn;
QString randomPhn = phoneNumbers.at(random % phoneNumbers.size());
phn.setNumber(preventAggregate ? QString(QString::number(random % 500000) + randomPhn) : randomPhn);
if ((random % 9) == 0) phn.setContexts(QContactDetail::ContextWork);
retn.saveDetail(&phn);
}
// Email
if ((random % 2) == 0) {
QContactEmailAddress em;
em.setEmailAddress(QString(QLatin1String("%1%2%3%4"))
.arg(preventAggregate ? QString(QString::number(random % 500000) + syncTarget) : QString())
.arg(name.firstName()).arg(name.lastName())
.arg(emailProviders.at(random % emailProviders.size())));
if (random % 9) em.setContexts(QContactDetail::ContextWork);
retn.saveDetail(&em);
}
// Avatar
if ((random % 5) == 0) {
QContactAvatar av;
av.setImageUrl(name.firstName() + avatars.at(random % avatars.size()));
retn.saveDetail(&av);
}
// Hobby
if ((random % 21) == 0) {
QContactHobby h1;
h1.setHobby(hobbies.at(random % hobbies.size()));
retn.saveDetail(&h1);
int newRandom = qrand();
if ((newRandom % 2) == 0) {
QContactHobby h2;
h2.setHobby(hobbies.at(newRandom % hobbies.size()));
retn.saveDetail(&h2);
}
}
return retn;
}
示例6: reset
void SeasideCache::reset()
{
for (int i = 0; i < FilterTypesCount; ++i) {
m_contacts[i].clear();
m_populated[i] = false;
m_models[i] = 0;
}
m_cache.clear();
m_cacheIndices.clear();
for (uint i = 0; i < sizeof(contactsData) / sizeof(Contact); ++i) {
QContact contact;
// This is specific to the qtcontacts-sqlite backend:
const QString idStr(QString::fromLatin1("qtcontacts:org.nemomobile.contacts.sqlite::sql-%1"));
contact.setId(QContactId::fromString(idStr.arg(i + 1)));
QContactName name;
name.setFirstName(QString::fromLatin1(contactsData[i].firstName));
name.setMiddleName(QString::fromUtf8(contactsData[i].middleName));
name.setLastName(QString::fromLatin1(contactsData[i].lastName));
contact.saveDetail(&name);
if (contactsData[i].avatar) {
QContactAvatar avatar;
avatar.setImageUrl(QUrl(QLatin1String(contactsData[i].avatar)));
contact.saveDetail(&avatar);
}
QContactStatusFlags statusFlags;
if (contactsData[i].email) {
QContactEmailAddress email;
email.setEmailAddress(QLatin1String(contactsData[i].email));
contact.saveDetail(&email);
statusFlags.setFlag(QContactStatusFlags::HasEmailAddress, true);
}
if (contactsData[i].phoneNumber) {
QContactPhoneNumber phoneNumber;
phoneNumber.setNumber(QLatin1String(contactsData[i].phoneNumber));
contact.saveDetail(&phoneNumber);
statusFlags.setFlag(QContactStatusFlags::HasPhoneNumber, true);
}
contact.saveDetail(&statusFlags);
m_cacheIndices.insert(internalId(contact), m_cache.count());
m_cache.append(CacheItem(contact));
QString fullName = name.firstName() + QChar::fromLatin1(' ') + name.lastName();
CacheItem &cacheItem = m_cache.last();
cacheItem.nameGroup = determineNameGroup(&cacheItem);
cacheItem.displayLabel = fullName;
}
insert(FilterAll, 0, getContactsForFilterType(FilterAll));
insert(FilterFavorites, 0, getContactsForFilterType(FilterFavorites));
insert(FilterOnline, 0, getContactsForFilterType(FilterOnline));
}
示例7: testDescriptor
void tst_QContactActions::testDescriptor()
{
// first, test retrieving an invalid action
QContactAction* invalidAction = QContactAction::action(QContactActionDescriptor());
QVERIFY(invalidAction == 0); // should be null.
QContact c;
QContactEmailAddress e;
e.setEmailAddress("[email protected]");
c.saveDetail(&e);
QContactPhoneNumber p;
p.setNumber("12345");
c.saveDetail(&p);
QVERIFY(QContactAction::availableActions().contains("SendEmail"));
QVERIFY(QContactAction::availableActions("tst_qcontactactions:sendemailaction").contains("SendEmail"));
QContactActionDescriptor sendEmailDescriptor;
QContactActionDescriptor multiActionOneDescriptor;
QContactActionDescriptor multiActionTwoDescriptor;
QList<QContactActionDescriptor> descrs = QContactAction::actionDescriptors();
QContactAction* sendEmailAction = 0;
for (int i = 0; i < descrs.size(); i++) {
QContactActionDescriptor temp = descrs.at(i);
if (temp.actionName() == QString("SendEmail")) {
sendEmailAction = QContactAction::action(temp);
QVERIFY(c.availableActions().contains(temp)); // has an email address, so should be available
QVERIFY(temp.supportsContact(c));
sendEmailDescriptor = temp;
} else if (temp.actionName() == QString("call")) {
if (temp.metaData(QString(QLatin1String("Provider"))) == QString(QLatin1String("sip"))) {
multiActionOneDescriptor = temp;
} else {
multiActionTwoDescriptor = temp;
}
}
}
QVERIFY(sendEmailDescriptor.isValid());
QVERIFY(multiActionOneDescriptor.isValid());
QVERIFY(multiActionTwoDescriptor.isValid());
QVERIFY(sendEmailAction != 0);
delete sendEmailAction;
// now test equivalence. The send email action descriptor should
// have a different action name to both multi action one and two.
QVERIFY(sendEmailDescriptor.actionName() != multiActionOneDescriptor.actionName());
QVERIFY(sendEmailDescriptor.actionName() != multiActionTwoDescriptor.actionName());
QVERIFY(sendEmailDescriptor != multiActionOneDescriptor);
QVERIFY(sendEmailDescriptor != multiActionTwoDescriptor);
// multi action one and two should have the same action name, service
// name and implementation (minor) version. BUT they have different
// implementations (Provider is different) so they should NOT be equal.
QVERIFY(multiActionOneDescriptor.actionName() == multiActionTwoDescriptor.actionName());
QVERIFY(multiActionOneDescriptor.serviceName() == multiActionTwoDescriptor.serviceName());
QVERIFY(multiActionOneDescriptor.implementationVersion() == multiActionTwoDescriptor.implementationVersion());
QVERIFY(multiActionOneDescriptor != multiActionTwoDescriptor);
// verify that the meta data is reported correctly
QVERIFY(multiActionOneDescriptor.metaData("Provider") != multiActionTwoDescriptor.metaData("Provider"));
}
示例8: testSendEmail
void tst_QContactActions::testSendEmail()
{
QContact c;
QContactEmailAddress e;
e.setEmailAddress("[email protected]");
c.saveDetail(&e);
QVERIFY(QContactAction::availableActions().contains("SendEmail"));
QVERIFY(QContactAction::availableActions("tst_qcontactactions:sendemailaction").contains("SendEmail"));
QList<QContactActionDescriptor> descrs = QContactAction::actionDescriptors();
bool foundSendEmail = false;
for (int i = 0; i < descrs.size(); i++) {
if (descrs.at(i).actionName() == QString("SendEmail")) {
foundSendEmail = true;
break;
}
}
QVERIFY(foundSendEmail);
descrs = QContactAction::actionDescriptors(QString());
foundSendEmail = false;
for (int i = 0; i < descrs.size(); i++) {
QCOMPARE(descrs.at(i).serviceName(), QString("tst_qcontactactions:sendemailaction"));
if (descrs.at(i).actionName() == QString("SendEmail")) {
foundSendEmail = true;
break;
}
}
QVERIFY(foundSendEmail);
descrs = QContactAction::actionDescriptors(QString());
foundSendEmail = false;
for (int i = 0; i < descrs.size(); i++) {
QCOMPARE(descrs.at(i).serviceName(), QString("tst_qcontactactions:sendemailaction"));
QCOMPARE(descrs.at(i).implementationVersion(), 1);
if (descrs.at(i).actionName() == QString("SendEmail")
&& descrs.at(i).serviceName() == QString("tst_qcontactactions:sendemailaction")
&& descrs.at(i).implementationVersion() == 1) {
foundSendEmail = true;
break;
}
}
QVERIFY(foundSendEmail);
descrs = QContactAction::actionDescriptors("SendEmail");
foundSendEmail = false;
for (int i = 0; i < descrs.size(); i++) {
QCOMPARE(descrs.at(i).actionName(), QString("SendEmail"));
if (descrs.at(i).actionName() == QString("SendEmail")
&& descrs.at(i).serviceName() == QString("tst_qcontactactions:sendemailaction")
&& descrs.at(i).implementationVersion() == 1) {
foundSendEmail = true;
break;
}
}
QVERIFY(foundSendEmail);
descrs = QContactAction::actionDescriptors();
QContactAction* sendEmail = 0;
for (int i = 0; i < descrs.size(); i++) {
if (descrs.at(i).actionName() == QString("SendEmail")
&& descrs.at(i).serviceName() == QString("tst_qcontactactions:sendemailaction")
&& descrs.at(i).implementationVersion() == 1) {
sendEmail = QContactAction::action(descrs.at(i));
break;
}
}
QVERIFY(sendEmail);
}
示例9: contactFunctions
void tst_QContactActions::contactFunctions()
{
QContact c; // empty contact.
QContact c2; // contact with email saved.
QContact c3; // two emails
QContact c4; // two emails, plus a preference
QContact c5; // two emails, plus a preference for an unsupported detail
QContactEmailAddress e2;
QContactEmailAddress e;
e.setEmailAddress("[email protected]");
c2.saveDetail(&e);
e2.setEmailAddress("[email protected]");
c3.saveDetail(&e);
c3.saveDetail(&e2);
c4.saveDetail(&e);
c4.saveDetail(&e2);
c5.saveDetail(&e2); // reverse order for c5
c5.saveDetail(&e);
c4.setPreferredDetail("SendEmail", e2);
c5.setPreferredDetail("SendEmail", c5.detail<QContactDisplayLabel>());
// Get our descriptor
QContactActionDescriptor descriptor = QContactAction::actionDescriptors("SendEmail").value(0);
QVERIFY(descriptor.actionName() == "SendEmail");
// available actions:
// empty contact
QList<QContactActionDescriptor> availableActions = c.availableActions(QString());
QVERIFY(availableActions.isEmpty()); // should not contain SendEmail
// contact with email
availableActions = c2.availableActions(QString());
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
QVERIFY(availableActions.contains(descriptor));
// try various combinations of version and name
availableActions = c2.availableActions();
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
QVERIFY(availableActions.contains(descriptor));
availableActions = c2.availableActions("tst_qcontactactions:sendemailaction");
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
availableActions = c2.availableActions(QString());
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
QVERIFY(availableActions.contains(descriptor));
// Again with c3
availableActions = c3.availableActions(QString());
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
QVERIFY(availableActions.contains(descriptor));
// try various combinations of version and name
availableActions = c3.availableActions();
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
QVERIFY(availableActions.contains(descriptor));
availableActions = c3.availableActions("tst_qcontactactions:sendemailaction");
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
QVERIFY(availableActions.contains(descriptor));
availableActions = c3.availableActions(QString());
QVERIFY(!availableActions.isEmpty()); // should contain SendEmail
QVERIFY(availableActions.contains(descriptor));
}
示例10: createComplexContacts
void SymbianPluginPerfomance::createComplexContacts()
{
// Create N contacts
QList<QContact> contactsList;
for(int i=0; i<NO_OF_CONTACTS; i++) {
QContact alice;
// Contact details
QString c = QString::number(i);
QString first("Alice");
QString last("Jones");
QContactName aliceName;
aliceName.setFirstName(first.append(c));
aliceName.setLastName(last.append(c));
alice.saveDetail(&aliceName);
QContactPhoneNumber number;
number.setContexts("Home");
number.setSubTypes("Mobile");
number.setNumber("12345678");
alice.saveDetail(&number);
alice.setPreferredDetail("DialAction", number);
QContactPhoneNumber number2;
number2.setContexts("Work");
number2.setSubTypes("Landline");
number2.setNumber("555-4444");
alice.saveDetail(&number2);
QContactAddress add;
add.setStreet("Leeds West Yorkshire");
add.setPostcode("10087");
add.setRegion("New York");
add.setCountry("United States");
alice.saveDetail(&add);
/* Commented out to ensure compatibility with pre-10.1 platforms
QContactGender gender;
gender.setGender("Female");
alice.saveDetail(&gender);
*/
QContactBirthday bday;
bday.setDate(QDate(25,10,1978));
alice.saveDetail(&bday);
/* Commented out to ensure compatibility with pre-10.1 platforms
QContactOnlineAccount acc;
acc.setAccountUri("sips:[email protected]");
acc.setSubTypes(QContactOnlineAccount::SubTypeSip);
alice.saveDetail(&acc);
*/
QContactEmailAddress email;
email.setEmailAddress("mailto:[email protected]");
alice.saveDetail(&email);
QContactOrganization org;
org.setDepartment(QStringList("Services"));
org.setTitle("Assistant Manager");
// Commented out to ensure compatibility with pre-10.1 platforms
//org.setLocation("Nokia Cyber Park");
alice.saveDetail(&org);
contactsList.append(alice);
}
// Save the contacts
mTime.restart();
QMap<int, QContactManager::Error> errors;
mCntMng->saveContacts(&contactsList, &errors);
foreach(QContactManager::Error error, errors) {
QCOMPARE(error, QContactManager::NoError);
}
示例11: saveContactWithPreferredDetails
void TestSymbianEngine::saveContactWithPreferredDetails()
{
QContactManager::Error err;
//save a contact with preferred details
QContact c;
c.setType(QContactType::TypeContact);
QContactPhoneNumber number1;
number1.setNumber("123");
number1.setSubTypes(QContactPhoneNumber::SubTypeMobile);
c.saveDetail(&number1);
c.setPreferredDetail("call", number1);
QContactPhoneNumber number2;
number2.setNumber("456");
number2.setSubTypes(QContactPhoneNumber::SubTypeMobile);
c.saveDetail(&number2);
c.setPreferredDetail("videocall", number2);
QContactPhoneNumber number3;
number3.setNumber("789");
number3.setSubTypes(QContactPhoneNumber::SubTypeMobile);
c.saveDetail(&number3);
c.setPreferredDetail("message", number3);
QContactEmailAddress email;
email.setEmailAddress("dummyemail");
c.saveDetail(&email);
c.setPreferredDetail("email", email);
QContactOnlineAccount onlineAccount;
onlineAccount.setAccountUri("dummy");
onlineAccount.setSubTypes(QContactOnlineAccount::SubTypeImpp);
c.saveDetail(&onlineAccount);
c.setPreferredDetail("OnlineAccountActions", onlineAccount);
QContactUrl url;
url.setUrl("http://dummy");
c.saveDetail(&url);
c.setPreferredDetail("url", url);
QVERIFY(m_engine->saveContact(&c, &err));
QVERIFY(err == QContactManager::NoError);
//fetch the saved contact and check preferred details
QContactFetchHint hint = QContactFetchHint();
QContact fetched = m_engine->contact(c.localId(), hint, &err);
QVERIFY(err == QContactManager::NoError);
QContactDetail callDetail1 = fetched.preferredDetail("call");
QVERIFY(callDetail1.definitionName() == QContactPhoneNumber::DefinitionName);
QContactPhoneNumber fetchedNumber1 = static_cast<QContactPhoneNumber>(callDetail1);
QVERIFY(fetchedNumber1.number() == "123");
QContactDetail callDetail2 = fetched.preferredDetail("videocall");
QVERIFY(callDetail2.definitionName() == QContactPhoneNumber::DefinitionName);
QContactPhoneNumber fetchedNumber2 = static_cast<QContactPhoneNumber>(callDetail2);
QVERIFY(fetchedNumber2.number() == "456");
QContactDetail callDetail3 = fetched.preferredDetail("message");
QVERIFY(callDetail3.definitionName() == QContactPhoneNumber::DefinitionName);
QContactPhoneNumber fetchedNumber3 = static_cast<QContactPhoneNumber>(callDetail3);
QVERIFY(fetchedNumber3.number() == "789");
QContactDetail emailDetail = fetched.preferredDetail("email");
QVERIFY(emailDetail.definitionName() == QContactEmailAddress::DefinitionName);
QContactEmailAddress fetchedEmail = static_cast<QContactEmailAddress>(emailDetail);
QVERIFY(fetchedEmail.emailAddress() == "dummyemail");
QContactDetail onlineAccountDetail = fetched.preferredDetail("OnlineAccountActions");
QVERIFY(onlineAccountDetail.definitionName() == QContactOnlineAccount::DefinitionName);
QContactOnlineAccount fetchedOnlineAccount = static_cast<QContactOnlineAccount>(onlineAccountDetail);
QVERIFY(fetchedOnlineAccount.accountUri() == "dummy");
QContactDetail urlDetail = fetched.preferredDetail("url");
QVERIFY(urlDetail.definitionName() == QContactUrl::DefinitionName);
QContactUrl fetchedUrl = static_cast<QContactUrl>(urlDetail);
QVERIFY(fetchedUrl.url() == "http://dummy");
//save a contact with one preferred details for several actions
QContact c2;
c2.setType(QContactType::TypeContact);
c2.saveDetail(&number1);
c2.setPreferredDetail("call", number1);
c2.setPreferredDetail("videocall", number1);
c2.setPreferredDetail("message", number1);
QVERIFY(m_engine->saveContact(&c2, &err));
QVERIFY(err == QContactManager::NoError);
//fetch the saved contact and check preferred details
QContact fetched2 = m_engine->contact(c2.localId(), hint, &err);
QVERIFY(err == QContactManager::NoError);
QContactDetail callDetail4 = fetched2.preferredDetail("call");
QVERIFY(callDetail4.definitionName() == QContactPhoneNumber::DefinitionName);
QContactPhoneNumber fetchedNumber4 = static_cast<QContactPhoneNumber>(callDetail4);
QVERIFY(fetchedNumber4.number() == "123");
//.........这里部分代码省略.........