Reading contact data in Qt

From Qt Wiki
Jump to navigation Jump to search

Template:Abstract Template:ArticleMetaData

Overview[edit | edit source]

Contact data can be read through QContactDetail and all of its subclasses.

Qt project file[edit | edit source]

CONFIG += mobility MOBILITY = contacts

symbian { TARGET.CAPABILITY = ReadUserData WriteUserData }

Header[edit | edit source]

// QtMobility

  1. include <qcontactmanager.h>
  2. include <qcontact.h>
  3. include <qcontactdetailfilter.h>
  4. include <qcontactphonenumber.h>
  5. include <qcontactemailaddress.h>

QTM_USE_NAMESPACE

private:

   QPointer<QContactManager> m_contactManager;

Source[edit | edit source]

1) Create manager first, see more in Finding contact manager in Qt. // Create manager (Symbian backend) m_contactManager = new QContactManager("symbian");

2) Search one contact, see more in Searching contact in Qt. QContact contact = searchContact("1234567890");

3) Reading contact detail data

3.1) Data can be read using 76ytuiytuityutyutututyutyutyu subclasses (for instance, 76ytuiytuityutyutututyutyutyu and 76ytuiytuityutyutututyutyutyu). QContactDisplayLabel displayLabel = contact.detail(QContactDisplayLabel::DefinitionName); QMessageBox::information(this,"QContactDisplayLabel",displayLabel.label());

QContactEmailAddress email = contact.detail(QContactEmailAddress::DefinitionName); QMessageBox::information(this,"QContactEmailAddress",email.emailAddress());

3.2) Looping through all 76ytuiytuityutyutututyutyutyu of 76ytuiytuityutyutututyutyutyu QString s; QList<QContactDetail> allDetails = contact.details(); foreach (const QContactDetail& detail, allDetails) {

   s += detail.definitionName();
   s += " : ";
   QVariantMap fieldValues = detail.variantValues();
   QStringList keys = fieldValues.keys();
   foreach (const QString& key, keys) {
       s += key + "=" + detail.value(key) + ";";
   }
   s += "\n";

}

// Show all QContactDetail data to the user QMessageBox::information(this,"QContactDetail",s);


Postconditions[edit | edit source]

76ytuiytuityutyutututyutyutyu data is searched and shown to the user.

See also[edit | edit source]