Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 50facae208d4a6f280e44a513b104320 > files > 164

qt-mobility-doc-1.2.0-13.mga5.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- contactsusage.qdoc -->
  <title>Qt Mobility 1.2: Contacts API Usage</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>QtMobility Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li>Contacts API Usage</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#introduction">Introduction</a></li>
<li class="level1"><a href="#manager-settings-and-configuration">Manager Settings And Configuration</a></li>
<li class="level2"><a href="#loading-the-default-manager-for-the-platform">Loading the default manager for the platform</a></li>
<li class="level2"><a href="#querying-a-manager-for-capabilities">Querying a manager for capabilities</a></li>
<li class="level2"><a href="#loading-the-manager-for-a-specific-backend">Loading the manager for a specific backend</a></li>
<li class="level2"><a href="#loading-a-manager-with-specific-parameters">Loading a manager with specific parameters</a></li>
<li class="level1"><a href="#contact-detail-manipulation">Contact Detail Manipulation</a></li>
<li class="level2"><a href="#adding-a-detail-to-a-contact">Adding a detail to a contact</a></li>
<li class="level2"><a href="#updating-a-detail-in-a-contact">Updating a detail in a contact</a></li>
<li class="level2"><a href="#removing-a-detail-from-a-contact">Removing a detail from a contact</a></li>
<li class="level2"><a href="#viewing-a-specific-detail-of-a-contact">Viewing a specific detail of a contact</a></li>
<li class="level2"><a href="#viewing-all-of-the-details-of-a-contact">Viewing all of the details of a contact</a></li>
<li class="level1"><a href="#persistent-contact-information">Persistent Contact Information</a></li>
<li class="level2"><a href="#creating-a-new-contact-in-a-manager">Creating a new contact in a manager</a></li>
<li class="level2"><a href="#retrieving-contacts-from-a-manager">Retrieving contacts from a manager</a></li>
<li class="level2"><a href="#updating-an-existing-contact-in-a-manager">Updating an existing contact in a manager</a></li>
<li class="level2"><a href="#removing-a-contact-from-a-manager">Removing a contact from a manager</a></li>
<li class="level2"><a href="#creating-a-new-relationship-between-two-contacts">Creating a new relationship between two contacts</a></li>
<li class="level2"><a href="#retrieving-relationships-between-contacts">Retrieving relationships between contacts</a></li>
<li class="level2"><a href="#removing-a-relationship-between-two-contacts">Removing a relationship between two contacts</a></li>
<li class="level2"><a href="#querying-the-schema-supported-by-a-manager">Querying the schema supported by a manager</a></li>
<li class="level2"><a href="#modifying-the-schema-supported-by-a-manager">Modifying the schema supported by a manager</a></li>
</ul>
</div>
<h1 class="title">Contacts API Usage</h1>
<span class="subtitle"></span>
<!-- $$$contactsusage.html-description -->
<div class="descr"> <a name="details"></a>
<a name="introduction"></a>
<h2>Introduction</h2>
<p>This section provides some examples of common usage of the Qt Contacts API. The most common use of the API is to retrieve a contact and then display certain details of that contact. To do so, several steps must be taken:</p>
<ul>
<li>A contact manager must be instantiated</li>
<li>The contact must be retrieved from the manager</li>
<li>The required details of the contact must be selected from the contact</li>
</ul>
<p>The first step is usually as simple as:</p>
<pre class="cpp"> <span class="type"><a href="qcontactmanager.html">QContactManager</a></span> cm; <span class="comment">// instantiate the default manager</span></pre>
<p>The second step requires either a filtering operation, or, if the id of the contact is already known, a direct selection operation. If you are interested in all contacts, a &quot;default filter&quot; retrieve operation is used. The retrieval operations may either be <a href="contactssync.html">synchronous</a> or <a href="contactsasync.html">asynchronous</a>; we recommend using asynchronous operations for applications which require a responsive user interface. For simplicity, however, the example below uses the synchronous API to retrieve all contacts:</p>
<pre class="cpp"> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span> allContacts <span class="operator">=</span> cm<span class="operator">.</span>contacts();</pre>
<p>The third step may be performed in several ways. The recommended way is to utilize the templated detail accessor, if you know which type of detail you are interested in:</p>
<pre class="cpp"> <span class="type"><a href="qcontact.html">QContact</a></span> firstContact <span class="operator">=</span> allContacts<span class="operator">.</span>first();
 <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The first contact has a phone number:&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> firstContact<span class="operator">.</span>detail<span class="operator">&lt;</span><span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">&gt;</span>()<span class="operator">.</span>number();</pre>
<p>Alternatively, you can use the base <a href="qcontactdetail.html">QContactDetail</a> class methods to select the detail in which you are interested in, and the field keys specified in the derived class to select the value which you are interested in:</p>
<pre class="cpp"> <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The first contact has a phone number:&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> firstContact<span class="operator">.</span>detail(<span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">::</span>DefinitionName)<span class="operator">.</span>value(<span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">::</span>FieldNumber);</pre>
<p>Note that in each case, if the contact did not have a phone number detail, the return value of <a href="qcontact.html#detail">QContact::detail</a>() is an empty detail. Also note that in the first case, the return value will be of the <a href="qcontactphonenumber.html">QContactPhoneNumber</a> detail type, whereas in the second case, the return value will be of the <a href="qcontactdetail.html">QContactDetail</a> (base-class detail) type -- although the actual detail returned in both cases is exactly the same.</p>
<p>If you wish to retrieve all of the details of a contact, you may do something similar to:</p>
<pre class="cpp"> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactdetail.html">QContactDetail</a></span><span class="operator">&gt;</span> allDetails <span class="operator">=</span> firstContact<span class="operator">.</span>details();</pre>
<p>Alternatively, if you wish only to retrieve the details which are of some particular type, you can use either the templated or non-templated accessor:</p>
<pre class="cpp"> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">&gt;</span> allPhoneNumbers <span class="operator">=</span> firstContact<span class="operator">.</span>details<span class="operator">&lt;</span><span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">&gt;</span>();
 <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactdetail.html">QContactDetail</a></span><span class="operator">&gt;</span> allPhoneNumbers2 <span class="operator">=</span> firstContact<span class="operator">.</span>details(<span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">::</span>DefinitionName);</pre>
<p>Note that in each case, if the contact did not have any phone number details, the return value of <a href="qcontact.html#details">QContact::details</a>() is an empty list. Also note that in the first case, the return value will be a list of the <a href="qcontactphonenumber.html">QContactPhoneNumber</a> detail type, whereas in the second case, the return value will be a list of the <a href="qcontactdetail.html">QContactDetail</a> (base-class detail) type -- although the actual details returned in both cases will be exactly the same.</p>
<p>The next most common use of the API is to save a contact. Such an operation consists of two steps:</p>
<ul>
<li>Saving a detail in a contact</li>
<li>Saving the contact in a manager</li>
</ul>
<p>Removing a contact is done similarly to saving a contact. An example of these two operations is given below. Note that it uses the synchronous API to save and remove the contact, although in a real application we recommend using the asynchronous API to perform such manager-related operations.</p>
<pre class="cpp"> <span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span> newPhoneNumber;       <span class="comment">// create the detail to add</span>
 newPhoneNumber<span class="operator">.</span>setNumber(<span class="string">&quot;12345&quot;</span>);        <span class="comment">// set the value(s) to save</span>
 firstContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>newPhoneNumber); <span class="comment">// save the detail in the contact</span>
 cm<span class="operator">.</span>saveContact(<span class="operator">&amp;</span>firstContact);            <span class="comment">// save the contact in the manager</span>
 cm<span class="operator">.</span>removeContact(firstContact<span class="operator">.</span>localId()); <span class="comment">// remove the contact from the manager</span></pre>
<p>That's it! For more in-depth discussion of usage of the API, see the sections below.</p>
<a name="manager-settings-and-configuration"></a>
<h2>Manager Settings And Configuration</h2>
<p>Users of the contacts API can define which backend they wish to access if a manager for that backend is available. The list of available managers can be queried programmatically at run-time, and the capabilities of different managers can be ascertained by inspecting a <a href="qcontactmanager.html">QContactManager</a> instance. Furthermore, some managers can be constructed with parameters which affect the operation of the backend.</p>
<a name="loading-the-default-manager-for-the-platform"></a>
<h3>Loading the default manager for the platform</h3>
<p>Most users of the API will want to use the default manager for the platform, which provides access to the system address book. Instantiating a manager by using the default constructor will result in the default manager for that platform being instantiated.</p>
<p>The default constructor can either be used to create a manager on the stack, in which case it will be deleted automatically when it goes out of scope:</p>
<pre class="cpp">     <span class="type"><a href="qcontactmanager.html">QContactManager</a></span> stackDefaultContactManager;</pre>
<p>or it can be used explicitly to create a manager on the heap, in which case the client must ensure that they delete the manager when they are finished with it in order to avoid a memory leak:</p>
<pre class="cpp">     <span class="type"><a href="qcontactmanager.html">QContactManager</a></span> <span class="operator">*</span>heapDefaultContactManager <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcontactmanager.html">QContactManager</a></span>;
     <span class="comment">// ... perform contact manipulation</span>
     <span class="keyword">delete</span> heapDefaultContactManager;</pre>
<a name="querying-a-manager-for-capabilities"></a>
<h3>Querying a manager for capabilities</h3>
<p>Different managers will support different capabilities and details. Clients can use the meta data reporting functions of <a href="qcontactmanager.html">QContactManager</a> to determine what the capabilities of the manager they have instantiated might be.</p>
<pre class="cpp">     <span class="type"><a href="qcontactmanager.html">QContactManager</a></span> cm;
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The default manager for the platform is:&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> cm<span class="operator">.</span>managerName();
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;It&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> (cm<span class="operator">.</span>isRelationshipTypeSupported(<span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>HasAssistant) <span class="operator">?</span> <span class="string">&quot;supports&quot;</span> : <span class="string">&quot;does not support&quot;</span>) <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;assistant relationships.&quot;</span>;
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;It&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> (cm<span class="operator">.</span>supportedContactTypes()<span class="operator">.</span>contains(<span class="type"><a href="qcontacttype.html">QContactType</a></span><span class="operator">::</span>TypeGroup) <span class="operator">?</span> <span class="string">&quot;supports&quot;</span> : <span class="string">&quot;does not support&quot;</span>) <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;groups.&quot;</span>;
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;It&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> (cm<span class="operator">.</span>hasFeature(<span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">::</span>MutableDefinitions) <span class="operator">?</span> <span class="string">&quot;supports&quot;</span> : <span class="string">&quot;does not support&quot;</span>) <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;mutable detail definitions.&quot;</span>;</pre>
<a name="loading-the-manager-for-a-specific-backend"></a>
<h3>Loading the manager for a specific backend</h3>
<p>In this example, the client loads a manager for a specific backend. While this could be found and retrieved using a more advanced plugin framework (such as the Qt Service Framework), this code assumes that the client has prior knowledge of the backend in question.</p>
<p>Clients may wish to use this feature of the API if they wish to store or retrieve contact information to a particular manager (for example, one that interfaces with a particular online service).</p>
<pre class="cpp">     <span class="type"><a href="qcontactmanager.html">QContactManager</a></span> contactManager(<span class="string">&quot;KABC&quot;</span>);</pre>
<a name="loading-a-manager-with-specific-parameters"></a>
<h3>Loading a manager with specific parameters</h3>
<p>The client loads a manager with specific parameters defined. The parameters which are available are backend specific, and so the client had to know that the &quot;Settings&quot; parameter was valid for the particular backend, and what argument it took. In this example, the client tells the backend to load detail definitions saved in a particular settings file.</p>
<pre class="cpp">     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qmap.html">QMap</a></span><span class="operator">&lt;</span><span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span><span class="operator">,</span> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span><span class="operator">&gt;</span> parameters;
     parameters<span class="operator">.</span>insert(<span class="string">&quot;Settings&quot;</span><span class="operator">,</span> <span class="string">&quot;~/.qcontactmanager-kabc-settings.ini&quot;</span>);
     <span class="type"><a href="qcontactmanager.html">QContactManager</a></span> contactManager(<span class="string">&quot;KABC&quot;</span><span class="operator">,</span> parameters);</pre>
<a name="contact-detail-manipulation"></a>
<h2>Contact Detail Manipulation</h2>
<p>Once a contact has been created (or retrieved from a manager), the client can retrieve, create, update or delete details from the contact. Since <a href="qcontact.html">QContact</a> and <a href="qcontactdetail.html">QContactDetail</a> are both container (value) classes, the API offered for these operations is purely synchronous.</p>
<p>A contact consists of the details it contains, as well as an id. Some details are read-only (such as the display label of a contact) or irremovable (like the type of a contact), but most are freely modifiable by clients.</p>
<a name="adding-a-detail-to-a-contact"></a>
<h3>Adding a detail to a contact</h3>
<p>The client adds a name and a phone number to a contact.</p>
<pre class="cpp">     <span class="type"><a href="qcontact.html">QContact</a></span> exampleContact;

     <span class="type"><a href="qcontactname.html">QContactName</a></span> nameDetail;
     nameDetail<span class="operator">.</span>setFirstName(<span class="string">&quot;Adam&quot;</span>);
     nameDetail<span class="operator">.</span>setLastName(<span class="string">&quot;Unlikely&quot;</span>);

     <span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span> phoneNumberDetail;
     phoneNumberDetail<span class="operator">.</span>setNumber(<span class="string">&quot;+123 4567&quot;</span>);

     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>nameDetail);
     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>phoneNumberDetail);</pre>
<a name="updating-a-detail-in-a-contact"></a>
<h3>Updating a detail in a contact</h3>
<p>The client updates the phone number of a contact.</p>
<pre class="cpp">     phoneNumberDetail<span class="operator">.</span>setNumber(<span class="string">&quot;+123 9876&quot;</span>);
     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>phoneNumberDetail); <span class="comment">// overwrites old value on save</span></pre>
<a name="removing-a-detail-from-a-contact"></a>
<h3>Removing a detail from a contact</h3>
<p>The client removes the phone number of a contact.</p>
<pre class="cpp">     exampleContact<span class="operator">.</span>removeDetail(<span class="operator">&amp;</span>phoneNumberDetail);</pre>
<a name="viewing-a-specific-detail-of-a-contact"></a>
<h3>Viewing a specific detail of a contact</h3>
<p>The client retrieves and displays the first phone number of a contact</p>
<pre class="cpp"> <span class="type">void</span> viewSpecificDetail(<span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">*</span> cm)
 {
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactid.html#QContactLocalId-typedef">QContactLocalId</a></span><span class="operator">&gt;</span> contactIds <span class="operator">=</span> cm<span class="operator">-</span><span class="operator">&gt;</span>contactIds();
     <span class="type"><a href="qcontact.html">QContact</a></span> a <span class="operator">=</span> cm<span class="operator">-</span><span class="operator">&gt;</span>contact(contactIds<span class="operator">.</span>first());
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;The first phone number of&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>displayLabel()
              <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>detail(<span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">::</span>DefinitionName)<span class="operator">.</span>value(<span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">::</span>FieldNumber);
 }</pre>
<a name="viewing-all-of-the-details-of-a-contact"></a>
<h3>Viewing all of the details of a contact</h3>
<p>The client retrieves all of the details of a contact, and displays them</p>
<pre class="cpp"> <span class="type">void</span> viewDetails(<span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">*</span> cm)
 {
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactid.html#QContactLocalId-typedef">QContactLocalId</a></span><span class="operator">&gt;</span> contactIds <span class="operator">=</span> cm<span class="operator">-</span><span class="operator">&gt;</span>contactIds();
     <span class="type"><a href="qcontact.html">QContact</a></span> a <span class="operator">=</span> cm<span class="operator">-</span><span class="operator">&gt;</span>contact(contactIds<span class="operator">.</span>first());
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Viewing the details of&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>displayLabel();

     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactdetail.html">QContactDetail</a></span><span class="operator">&gt;</span> allDetails <span class="operator">=</span> a<span class="operator">.</span>details();
     <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> allDetails<span class="operator">.</span>size(); i<span class="operator">+</span><span class="operator">+</span>) {
         <span class="type"><a href="qcontactdetail.html">QContactDetail</a></span> detail <span class="operator">=</span> allDetails<span class="operator">.</span>at(i);
         <span class="type"><a href="qcontactdetaildefinition.html">QContactDetailDefinition</a></span> currentDefinition <span class="operator">=</span> cm<span class="operator">-</span><span class="operator">&gt;</span>detailDefinition(detail<span class="operator">.</span>definitionName());
         <span class="type"><a href="http://qt.nokia.com/doc/4.7/qmap.html">QMap</a></span><span class="operator">&lt;</span><span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span><span class="operator">,</span> <span class="type"><a href="qcontactdetailfielddefinition.html">QContactDetailFieldDefinition</a></span><span class="operator">&gt;</span> fields <span class="operator">=</span> currentDefinition<span class="operator">.</span>fields();

         <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>(<span class="string">&quot;\tDetail #%d (%s):&quot;</span><span class="operator">,</span> i<span class="operator">,</span> detail<span class="operator">.</span>definitionName()<span class="operator">.</span>toAscii()<span class="operator">.</span>constData());
         foreach (<span class="keyword">const</span> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span><span class="operator">&amp;</span> fieldKey<span class="operator">,</span> fields<span class="operator">.</span>keys()) {
             <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\t\t&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> fieldKey <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;(&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> fields<span class="operator">.</span>value(fieldKey)<span class="operator">.</span>dataType() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;) =&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> detail<span class="operator">.</span>value(fieldKey);
         }
         <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>();
     }
 }</pre>
<p>It is important to note that details are implicitly shared objects with particular semantics surrounding saving, removal and modification. The following example demonstrates these semantics</p>
<pre class="cpp"> <span class="type">void</span> detailSharing(<span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">*</span> cm)
 {
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactid.html#QContactLocalId-typedef">QContactLocalId</a></span><span class="operator">&gt;</span> contactIds <span class="operator">=</span> cm<span class="operator">-</span><span class="operator">&gt;</span>contactIds();
     <span class="type"><a href="qcontact.html">QContact</a></span> a <span class="operator">=</span> cm<span class="operator">-</span><span class="operator">&gt;</span>contact(contactIds<span class="operator">.</span>first());
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Demonstrating detail sharing semantics with&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>displayLabel();

     <span class="comment">/* Create a new phone number detail. */</span>
     <span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span> newNumber;
     newNumber<span class="operator">.</span>setNumber(<span class="string">&quot;123123123&quot;</span>);
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tThe new phone number is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> newNumber<span class="operator">.</span>number();

     <span class="comment">/*
      * Create a copy of that detail.  These will be implicitly shared;
      * changes to nnCopy will not affect newNumber, and vice versa.
      * However, attempting to save them will cause overwrite to occur.
      * Removal is done purely via key() checking, also.
      */</span>
     <span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span> nnCopy(newNumber);
     nnCopy<span class="operator">.</span>setNumber(<span class="string">&quot;456456456&quot;</span>);
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tThat number is still&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> newNumber<span class="operator">.</span>number() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, the copy is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> nnCopy<span class="operator">.</span>number();

     <span class="comment">/* Save the detail in the contact, then remove via the copy, then resave. */</span>
     a<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>newNumber);
     a<span class="operator">.</span>removeDetail(<span class="operator">&amp;</span>nnCopy);  <span class="comment">// identical to a.removeDetail(&amp;newNumber);</span>
     a<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>newNumber); <span class="comment">// since newNumber.key() == nnCopy.key();</span>

     <span class="comment">/* Saving will cause overwrite */</span>
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tPrior to saving nnCopy,&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>displayLabel() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;has&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>details()<span class="operator">.</span>count() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;details.&quot;</span>;
     a<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>nnCopy);
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tAfter saving nnCopy,&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>displayLabel() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;still has&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>details()<span class="operator">.</span>count() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;details.&quot;</span>;

     <span class="comment">/* In order to save nnCopy as a new detail, we must reset its key */</span>
     nnCopy<span class="operator">.</span>resetKey();
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tThe copy key is now&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> nnCopy<span class="operator">.</span>key() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, whereas the original key is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> newNumber<span class="operator">.</span>key();
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tPrior to saving (key reset) nnCopy,&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>displayLabel() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;has&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>details()<span class="operator">.</span>count() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;details.&quot;</span>;
     a<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>nnCopy);
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tAfter saving (key reset) nnCopy,&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>displayLabel() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;still has&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> a<span class="operator">.</span>details()<span class="operator">.</span>count() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;details.&quot;</span>;
     a<span class="operator">.</span>removeDetail(<span class="operator">&amp;</span>nnCopy);

     <span class="comment">/*
      * Note that changes made to details are not
      * propagated automatically to the contact.
      * To persist changes to a detail, you must call saveDetail().
      */</span>
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">&gt;</span> allNumbers <span class="operator">=</span> a<span class="operator">.</span>details<span class="operator">&lt;</span><span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">&gt;</span>();
     foreach (<span class="keyword">const</span> <span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">&amp;</span> savedPhn<span class="operator">,</span> allNumbers) {
         <span class="keyword">if</span> (savedPhn<span class="operator">.</span>key() <span class="operator">!</span><span class="operator">=</span> newNumber<span class="operator">.</span>key()) {
             <span class="keyword">continue</span>;
         }

         <span class="comment">/*
          * This phone number is the saved copy of the newNumber detail.
          * It is detached from the newNumber detail, so changes to newNumber
          * shouldn't affect savedPhn until saveDetail() is called again.
          */</span>
         <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tCurrently, the (stack) newNumber is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> newNumber<span class="operator">.</span>number()
                  <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, and the saved newNumber is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> savedPhn<span class="operator">.</span>number();
         newNumber<span class="operator">.</span>setNumber(<span class="string">&quot;678678678&quot;</span>);
         <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tNow, the (stack) newNumber is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> newNumber<span class="operator">.</span>number()
                  <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, but the saved newNumber is&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> savedPhn<span class="operator">.</span>number();
     }

     <span class="comment">/*
      * Removal of the detail depends only on the key of the detail; the fact
      * that the values differ is not taken into account by the remove operation.
      */</span>
     a<span class="operator">.</span>removeDetail(<span class="operator">&amp;</span>newNumber) <span class="operator">?</span> <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tSucceeded in removing the temporary detail.&quot;</span>
                                : <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\tFailed to remove the temporary detail.\n&quot;</span>;
 }</pre>
<a name="persistent-contact-information"></a>
<h2>Persistent Contact Information</h2>
<p>After instantiating a manager, clients will wish to retrieve or modify contact information (including relationships and possibly detail definitions) which is persistently stored in the manager (for example, in a database or online cloud).</p>
<p>If the client wishes to use the asynchronous API, it is suggested that their class uses member variables for the manager and requests, similarly to:</p>
<pre class="cpp"> QTM_USE_NAMESPACE
 <span class="keyword">class</span> AsyncRequestExample : <span class="keyword">public</span> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qobject.html">QObject</a></span>
 {
     Q_OBJECT

 <span class="keyword">public</span>:
     AsyncRequestExample();
     <span class="operator">~</span>AsyncRequestExample();

 <span class="keyword">public</span> <span class="keyword">slots</span>:
     <span class="type">void</span> performRequests();

 <span class="keyword">private</span> <span class="keyword">slots</span>:
     <span class="type">void</span> contactFetchRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> contactSaveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> contactRemoveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> relationshipFetchRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> relationshipSaveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> relationshipRemoveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> definitionFetchRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> definitionSaveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);
     <span class="type">void</span> definitionRemoveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState);

 <span class="keyword">private</span>:
     <span class="type"><a href="qcontactmanager.html">QContactManager</a></span> <span class="operator">*</span>m_manager;
     <span class="type"><a href="qcontactfetchrequest.html">QContactFetchRequest</a></span> m_contactFetchRequest;
     <span class="type"><a href="qcontactsaverequest.html">QContactSaveRequest</a></span> m_contactSaveRequest;
     <span class="type"><a href="qcontactremoverequest.html">QContactRemoveRequest</a></span> m_contactRemoveRequest;
     <span class="type"><a href="qcontactrelationshipfetchrequest.html">QContactRelationshipFetchRequest</a></span> m_relationshipFetchRequest;
     <span class="type"><a href="qcontactrelationshipsaverequest.html">QContactRelationshipSaveRequest</a></span> m_relationshipSaveRequest;
     <span class="type"><a href="qcontactrelationshipremoverequest.html">QContactRelationshipRemoveRequest</a></span> m_relationshipRemoveRequest;
     <span class="type"><a href="qcontactdetaildefinitionfetchrequest.html">QContactDetailDefinitionFetchRequest</a></span> m_definitionFetchRequest;
     <span class="type"><a href="qcontactdetaildefinitionsaverequest.html">QContactDetailDefinitionSaveRequest</a></span> m_definitionSaveRequest;
     <span class="type"><a href="qcontactdetaildefinitionremoverequest.html">QContactDetailDefinitionRemoveRequest</a></span> m_definitionRemoveRequest;
 };</pre>
<p>This allows them to define slots which deal with the data as required when the state of the request changes:</p>
<pre class="cpp"> <span class="type">void</span> AsyncRequestExample<span class="operator">::</span>contactFetchRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State newState)
 {
     <span class="keyword">if</span> (newState <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>FinishedState) {
         <span class="type"><a href="qcontactfetchrequest.html">QContactFetchRequest</a></span> <span class="operator">*</span>request <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qcontactfetchrequest.html">QContactFetchRequest</a></span><span class="operator">*</span><span class="operator">&gt;</span>(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qobject.html">QObject</a></span><span class="operator">::</span>sender());
         <span class="keyword">if</span> (request<span class="operator">-</span><span class="operator">&gt;</span>error() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">::</span>NoError) {
             <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Error&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> request<span class="operator">-</span><span class="operator">&gt;</span>error() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;occurred during fetch request!&quot;</span>;
             <span class="keyword">return</span>;
         }

         <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span> results <span class="operator">=</span> request<span class="operator">-</span><span class="operator">&gt;</span>contacts();
         <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> results<span class="operator">.</span>size(); i<span class="operator">+</span><span class="operator">+</span>) {
             <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Retrieved contact:&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> results<span class="operator">.</span>at(i)<span class="operator">.</span>displayLabel();
         }
     } <span class="keyword">else</span> <span class="keyword">if</span> (newState <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>CanceledState) {
         <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Fetch operation canceled!&quot;</span>;
     }
 }</pre>
<p>Note that if the client is interested in receiving the results of the request as they become available, rather than only the final set of results once the request changes state (to <tt>FinishedState</tt>, for example), the client should instead connect the <a href="qcontactabstractrequest.html#resultsAvailable">QContactAbstractRequest::resultsAvailable</a>() signal to the slot which deals with the results.</p>
<a name="creating-a-new-contact-in-a-manager"></a>
<h3>Creating a new contact in a manager</h3>
<p>The client creates a new contact and saves it in a manager</p>
<pre class="cpp">     <span class="type"><a href="qcontact.html">QContact</a></span> exampleContact;

     <span class="type"><a href="qcontactname.html">QContactName</a></span> nameDetail;
     nameDetail<span class="operator">.</span>setFirstName(<span class="string">&quot;Adam&quot;</span>);
     nameDetail<span class="operator">.</span>setLastName(<span class="string">&quot;Unlikely&quot;</span>);

     <span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span> phoneNumberDetail;
     phoneNumberDetail<span class="operator">.</span>setNumber(<span class="string">&quot;+123 4567&quot;</span>);

     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>nameDetail);
     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>phoneNumberDetail);

     <span class="comment">// save the newly created contact in the manager</span>
     connect(<span class="operator">&amp;</span>m_contactSaveRequest<span class="operator">,</span> SIGNAL(stateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(contactSaveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State)));
     m_contactSaveRequest<span class="operator">.</span>setManager(m_manager);
     m_contactSaveRequest<span class="operator">.</span>setContacts(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleContact);
     m_contactSaveRequest<span class="operator">.</span>start();</pre>
<p>Alternatively, the client can explicitly block execution until the request is complete, by doing something like:</p>
<pre class="cpp">     m_contactSaveRequest<span class="operator">.</span>setManager(m_manager);
     m_contactSaveRequest<span class="operator">.</span>setContacts(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleContact);
     m_contactSaveRequest<span class="operator">.</span>start();
     m_contactSaveRequest<span class="operator">.</span>waitForFinished();
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span> savedContacts <span class="operator">=</span> m_contactSaveRequest<span class="operator">.</span>contacts();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     <span class="type"><a href="qcontact.html">QContact</a></span> exampleContact;

     <span class="type"><a href="qcontactname.html">QContactName</a></span> nameDetail;
     nameDetail<span class="operator">.</span>setFirstName(<span class="string">&quot;Adam&quot;</span>);
     nameDetail<span class="operator">.</span>setLastName(<span class="string">&quot;Unlikely&quot;</span>);

     <span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span> phoneNumberDetail;
     phoneNumberDetail<span class="operator">.</span>setNumber(<span class="string">&quot;+123 4567&quot;</span>);

     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>nameDetail);
     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>phoneNumberDetail);

     <span class="comment">// save the newly created contact in the manager</span>
     <span class="keyword">if</span> (<span class="operator">!</span>m_manager<span class="operator">.</span>saveContact(<span class="operator">&amp;</span>exampleContact))
         <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Error&quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> m_manager<span class="operator">.</span>error() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;occurred whilst saving contact!&quot;</span>;</pre>
<a name="retrieving-contacts-from-a-manager"></a>
<h3>Retrieving contacts from a manager</h3>
<p>The client requests all contacts from the manager which match a particular filter.</p>
<pre class="cpp">     connect(<span class="operator">&amp;</span>m_contactFetchRequest<span class="operator">,</span> SIGNAL(stateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(contactFetchRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State)));
     m_contactFetchRequest<span class="operator">.</span>setManager(m_manager);
     m_contactFetchRequest<span class="operator">.</span>setFilter(<span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">::</span>match(<span class="string">&quot;+123 4567&quot;</span>));
     m_contactFetchRequest<span class="operator">.</span>start();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span> results <span class="operator">=</span> m_manager<span class="operator">.</span>contacts(<span class="type"><a href="qcontactphonenumber.html">QContactPhoneNumber</a></span><span class="operator">::</span>match(<span class="string">&quot;+123 4567&quot;</span>));</pre>
<p>The client can also retrieve a particular existing contact from a manager, by directly requesting the contact with a particular (previously known) id. With the asynchronous API, this takes the form of another filter:</p>
<pre class="cpp">     <span class="type"><a href="qcontactlocalidfilter.html">QContactLocalIdFilter</a></span> idListFilter;
     idListFilter<span class="operator">.</span>setIds(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactid.html#QContactLocalId-typedef">QContactLocalId</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleContact<span class="operator">.</span>localId());
     m_contactFetchRequest<span class="operator">.</span>setManager(m_manager);
     m_contactFetchRequest<span class="operator">.</span>setFilter(idListFilter);
     m_contactFetchRequest<span class="operator">.</span>start();</pre>
<p>The synchronous API provides a function specifically for this purpose:</p>
<pre class="cpp">     <span class="type"><a href="qcontact.html">QContact</a></span> existing <span class="operator">=</span> m_manager<span class="operator">.</span>contact(exampleContact<span class="operator">.</span>localId());</pre>
<a name="updating-an-existing-contact-in-a-manager"></a>
<h3>Updating an existing contact in a manager</h3>
<p>The client updates a previously saved contact by saving the updated version of the contact. Any contact whose id is the same as that of the updated contact will be overwritten as a result of the save request.</p>
<pre class="cpp">     phoneNumberDetail<span class="operator">.</span>setNumber(<span class="string">&quot;+123 9876&quot;</span>);
     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>phoneNumberDetail);
     m_contactSaveRequest<span class="operator">.</span>setManager(m_manager);
     m_contactSaveRequest<span class="operator">.</span>setContacts(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleContact);
     m_contactSaveRequest<span class="operator">.</span>start();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     phoneNumberDetail<span class="operator">.</span>setNumber(<span class="string">&quot;+123 9876&quot;</span>);
     exampleContact<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>phoneNumberDetail);
     m_manager<span class="operator">.</span>saveContact(<span class="operator">&amp;</span>exampleContact);</pre>
<a name="removing-a-contact-from-a-manager"></a>
<h3>Removing a contact from a manager</h3>
<p>The client removes a contact from the manager by specifying its local id.</p>
<pre class="cpp">     connect(<span class="operator">&amp;</span>m_contactRemoveRequest<span class="operator">,</span> SIGNAL(stateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(contactRemoveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State)));
     m_contactRemoveRequest<span class="operator">.</span>setManager(m_manager);
     m_contactRemoveRequest<span class="operator">.</span>setContactIds(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactid.html#QContactLocalId-typedef">QContactLocalId</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleContact<span class="operator">.</span>localId());
     m_contactRemoveRequest<span class="operator">.</span>start();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     m_manager<span class="operator">.</span>removeContact(exampleContact<span class="operator">.</span>localId());</pre>
<a name="creating-a-new-relationship-between-two-contacts"></a>
<h3>Creating a new relationship between two contacts</h3>
<p>The client specifies a relationship between two contacts stored in the manager</p>
<pre class="cpp">     <span class="comment">// first, create the group and the group member</span>
     <span class="type"><a href="qcontact.html">QContact</a></span> exampleGroup;
     exampleGroup<span class="operator">.</span>setType(<span class="type"><a href="qcontacttype.html">QContactType</a></span><span class="operator">::</span>TypeGroup);
     <span class="type"><a href="qcontactnickname.html">QContactNickname</a></span> groupName;
     groupName<span class="operator">.</span>setNickname(<span class="string">&quot;Example Group&quot;</span>);
     exampleGroup<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>groupName);

     <span class="type"><a href="qcontact.html">QContact</a></span> exampleGroupMember;
     <span class="type"><a href="qcontactname.html">QContactName</a></span> groupMemberName;
     groupMemberName<span class="operator">.</span>setFirstName(<span class="string">&quot;Member&quot;</span>);
     exampleGroupMember<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>groupMemberName);

     <span class="comment">// second, save those contacts in the manager</span>
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span> saveList;
     saveList <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleGroup <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleGroupMember;
     m_contactSaveRequest<span class="operator">.</span>setContacts(saveList);
     m_contactSaveRequest<span class="operator">.</span>start();
     m_contactSaveRequest<span class="operator">.</span>waitForFinished();

     <span class="comment">// third, create the relationship between those contacts</span>
     <span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span> groupRelationship;
     groupRelationship<span class="operator">.</span>setFirst(exampleGroup<span class="operator">.</span>id());
     groupRelationship<span class="operator">.</span>setRelationshipType(<span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>HasMember);
     groupRelationship<span class="operator">.</span>setSecond(exampleGroupMember<span class="operator">.</span>id());

     <span class="comment">// finally, save the relationship in the manager</span>
     connect(<span class="operator">&amp;</span>m_relationshipSaveRequest<span class="operator">,</span> SIGNAL(stateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(relationshipSaveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State)));
     m_relationshipSaveRequest<span class="operator">.</span>setManager(m_manager);
     m_relationshipSaveRequest<span class="operator">.</span>setRelationships(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> groupRelationship);
     m_relationshipSaveRequest<span class="operator">.</span>start();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     <span class="comment">// first, create the group and the group member</span>
     <span class="type"><a href="qcontact.html">QContact</a></span> exampleGroup;
     exampleGroup<span class="operator">.</span>setType(<span class="type"><a href="qcontacttype.html">QContactType</a></span><span class="operator">::</span>TypeGroup);
     <span class="type"><a href="qcontactnickname.html">QContactNickname</a></span> groupName;
     groupName<span class="operator">.</span>setNickname(<span class="string">&quot;Example Group&quot;</span>);
     exampleGroup<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>groupName);

     <span class="type"><a href="qcontact.html">QContact</a></span> exampleGroupMember;
     <span class="type"><a href="qcontactname.html">QContactName</a></span> groupMemberName;
     groupMemberName<span class="operator">.</span>setFirstName(<span class="string">&quot;Member&quot;</span>);
     exampleGroupMember<span class="operator">.</span>saveDetail(<span class="operator">&amp;</span>groupMemberName);

     <span class="comment">// second, save those contacts in the manager</span>
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qmap.html">QMap</a></span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">,</span> <span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">::</span>Error<span class="operator">&gt;</span> errorMap;
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span> saveList;
     saveList <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleGroup <span class="operator">&lt;</span><span class="operator">&lt;</span> exampleGroupMember;
     m_manager<span class="operator">.</span>saveContacts(<span class="operator">&amp;</span>saveList<span class="operator">,</span> <span class="operator">&amp;</span>errorMap);

     <span class="comment">// third, create the relationship between those contacts</span>
     <span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span> groupRelationship;
     groupRelationship<span class="operator">.</span>setFirst(exampleGroup<span class="operator">.</span>id());
     groupRelationship<span class="operator">.</span>setRelationshipType(<span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>HasMember);
     groupRelationship<span class="operator">.</span>setSecond(exampleGroupMember<span class="operator">.</span>id());

     <span class="comment">// finally, save the relationship in the manager</span>
     m_manager<span class="operator">.</span>saveRelationship(<span class="operator">&amp;</span>groupRelationship);</pre>
<a name="retrieving-relationships-between-contacts"></a>
<h3>Retrieving relationships between contacts</h3>
<p>The client requests the relationships that a particular contact is involved in from the manager in which the contact is stored.</p>
<pre class="cpp">     connect(<span class="operator">&amp;</span>m_relationshipFetchRequest<span class="operator">,</span> SIGNAL(stateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(relationshipFetchRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State)));
     m_relationshipFetchRequest<span class="operator">.</span>setManager(m_manager);
     <span class="comment">// retrieve the list of relationships between the example group contact and the example member contact</span>
     <span class="comment">// where the group contact is the first contact in the relationship, and the member contact is the</span>
     <span class="comment">// second contact in the relationship.  In order to fetch all relationships between them, another</span>
     <span class="comment">// relationship fetch must be performed with their roles reversed, and the results added together.</span>
     m_relationshipFetchRequest<span class="operator">.</span>setFirst(exampleGroup<span class="operator">.</span>id());
     m_relationshipFetchRequest<span class="operator">.</span>setSecond(exampleGroupMember<span class="operator">.</span>id());
     m_relationshipFetchRequest<span class="operator">.</span>start();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">&gt;</span> groupRelationships <span class="operator">=</span> m_manager<span class="operator">.</span>relationships(<span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>HasMember<span class="operator">,</span> exampleGroup<span class="operator">.</span>id()<span class="operator">,</span> <span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>First);
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">&gt;</span> result;
     <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> groupRelationships<span class="operator">.</span>size(); i<span class="operator">+</span><span class="operator">+</span>) {
         <span class="keyword">if</span> (groupRelationships<span class="operator">.</span>at(i)<span class="operator">.</span>second() <span class="operator">=</span><span class="operator">=</span> exampleGroupMember<span class="operator">.</span>id()) {
             result<span class="operator">.</span>append(groupRelationships<span class="operator">.</span>at(i));
         }
     }</pre>
<p>When a contact is retrieved, it will contain a cache of the relationships in which it is involved at the point in time at which it was retrieved. This provides clients with a simple way to retrieve the relationships in which a contact is involved, but carries the risk that the cache is stale.</p>
<pre class="cpp">     exampleGroup <span class="operator">=</span> m_manager<span class="operator">.</span>contact(exampleGroup<span class="operator">.</span>localId()); <span class="comment">// refresh the group contact</span>
     groupRelationships <span class="operator">=</span> exampleGroup<span class="operator">.</span>relationships(<span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>HasMember);
     <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> groupRelationships<span class="operator">.</span>size(); i<span class="operator">+</span><span class="operator">+</span>) {
         <span class="keyword">if</span> (groupRelationships<span class="operator">.</span>at(i)<span class="operator">.</span>second() <span class="operator">=</span><span class="operator">=</span> exampleGroupMember<span class="operator">.</span>id()) {
             result<span class="operator">.</span>append(groupRelationships<span class="operator">.</span>at(i));
         }
     }</pre>
<p>Clients can inform the manager that they do not require this cache of relationships to be populated when retrieving a contact, which can allow a manager to optimize contact retrieval. Other retrieval optimizations are also possible to specify, for example that they do not require action preferences to be returned, or that they are only interested in certain types of details. The following code shows how the client can inform the manager that they are only interested in relationships of the <tt>HasMember</tt> type (groups):</p>
<pre class="cpp">     <span class="type"><a href="qcontactfetchhint.html">QContactFetchHint</a></span> hasMemberRelationshipsOnly;
     hasMemberRelationshipsOnly<span class="operator">.</span>setRelationshipTypesHint(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qstringlist.html">QStringList</a></span>(<span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>HasMember));

     m_contactFetchRequest<span class="operator">.</span>setManager(m_manager);
     m_contactFetchRequest<span class="operator">.</span>setFilter(<span class="type"><a href="qcontactfilter.html">QContactFilter</a></span>()); <span class="comment">// all contacts</span>
     m_contactFetchRequest<span class="operator">.</span>setFetchHint(hasMemberRelationshipsOnly);
     m_contactFetchRequest<span class="operator">.</span>start();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     <span class="type"><a href="qcontactfetchhint.html">QContactFetchHint</a></span> hasMemberRelationshipsOnly;
     hasMemberRelationshipsOnly<span class="operator">.</span>setRelationshipTypesHint(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qstringlist.html">QStringList</a></span>(<span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">::</span>HasMember));

     <span class="comment">// retrieve all contacts, with no specified sort order, requesting that</span>
     <span class="comment">// HasMember relationships be included in the cache of result contacts</span>
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontact.html">QContact</a></span><span class="operator">&gt;</span> allContacts <span class="operator">=</span> m_manager<span class="operator">.</span>contacts(<span class="type"><a href="qcontactfilter.html">QContactFilter</a></span>()<span class="operator">,</span> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactsortorder.html">QContactSortOrder</a></span><span class="operator">&gt;</span>()<span class="operator">,</span> hasMemberRelationshipsOnly);</pre>
<a name="removing-a-relationship-between-two-contacts"></a>
<h3>Removing a relationship between two contacts</h3>
<p>The client can remove a relationship directly from a manager.</p>
<pre class="cpp">     connect(<span class="operator">&amp;</span>m_relationshipRemoveRequest<span class="operator">,</span> SIGNAL(stateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(relationshipRemoveRequestStateChanged(<span class="type"><a href="qcontactabstractrequest.html">QContactAbstractRequest</a></span><span class="operator">::</span>State)));
     m_relationshipRemoveRequest<span class="operator">.</span>setManager(m_manager);
     m_relationshipRemoveRequest<span class="operator">.</span>setRelationships(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactrelationship.html">QContactRelationship</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> groupRelationship);
     m_relationshipRemoveRequest<span class="operator">.</span>start();</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     m_manager<span class="operator">.</span>removeRelationship(groupRelationship);</pre>
<p>Alternatively, when a contact which is involved in a relationship is removed, any relationships in which it is involved will be removed also.</p>
<a name="querying-the-schema-supported-by-a-manager"></a>
<h3>Querying the schema supported by a manager</h3>
<p>The client queries the schema supported by a manager, and checks to see if a particular detail definition supports a certain field.</p>
<pre class="cpp">     m_definitionFetchRequest<span class="operator">.</span>setManager(m_manager);
     m_definitionFetchRequest<span class="operator">.</span>setDefinitionNames(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qstringlist.html">QStringList</a></span>(<span class="type"><a href="qcontactname.html">QContactName</a></span><span class="operator">::</span>DefinitionName));
     m_definitionFetchRequest<span class="operator">.</span>start();
     m_definitionFetchRequest<span class="operator">.</span>waitForFinished();
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qmap.html">QMap</a></span><span class="operator">&lt;</span><span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span><span class="operator">,</span> <span class="type"><a href="qcontactdetaildefinition.html">QContactDetailDefinition</a></span><span class="operator">&gt;</span> definitions <span class="operator">=</span> m_definitionFetchRequest<span class="operator">.</span>definitions();
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;This manager&quot;</span>
              <span class="operator">&lt;</span><span class="operator">&lt;</span> (definitions<span class="operator">.</span>value(<span class="type"><a href="qcontactname.html">QContactName</a></span><span class="operator">::</span>DefinitionName)<span class="operator">.</span>fields()<span class="operator">.</span>contains(<span class="type"><a href="qcontactname.html">QContactName</a></span><span class="operator">::</span>FieldCustomLabel) <span class="operator">?</span> <span class="string">&quot;supports&quot;</span> : <span class="string">&quot;does not support&quot;</span>)
              <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;the custom label field of QContactName&quot;</span>;</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qmap.html">QMap</a></span><span class="operator">&lt;</span><span class="type"><a href="http://qt.nokia.com/doc/4.7/qstring.html">QString</a></span><span class="operator">,</span> <span class="type"><a href="qcontactdetaildefinition.html">QContactDetailDefinition</a></span><span class="operator">&gt;</span> definitions <span class="operator">=</span> m_manager<span class="operator">.</span>detailDefinitions();
     <a href="http://qt.nokia.com/doc/4.7/qtglobal.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;This manager&quot;</span>
              <span class="operator">&lt;</span><span class="operator">&lt;</span> (definitions<span class="operator">.</span>value(<span class="type"><a href="qcontactname.html">QContactName</a></span><span class="operator">::</span>DefinitionName)<span class="operator">.</span>fields()<span class="operator">.</span>contains(<span class="type"><a href="qcontactname.html">QContactName</a></span><span class="operator">::</span>FieldCustomLabel) <span class="operator">?</span> <span class="string">&quot;supports&quot;</span> : <span class="string">&quot;does not support&quot;</span>)
              <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;the custom label field of QContactName&quot;</span>;</pre>
<a name="modifying-the-schema-supported-by-a-manager"></a>
<h3>Modifying the schema supported by a manager</h3>
<p>The client attempts to modify a particular detail definition by extending it so that it supports an extra field.</p>
<pre class="cpp">     <span class="comment">// modify the name definition, adding a patronym field</span>
     <span class="type"><a href="qcontactdetaildefinition.html">QContactDetailDefinition</a></span> nameDefinition <span class="operator">=</span> definitions<span class="operator">.</span>value(<span class="type"><a href="qcontactname.html">QContactName</a></span><span class="operator">::</span>DefinitionName);
     <span class="type"><a href="qcontactdetailfielddefinition.html">QContactDetailFieldDefinition</a></span> fieldPatronym;
     fieldPatronym<span class="operator">.</span>setDataType(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qvariant.html">QVariant</a></span><span class="operator">::</span>String);
     nameDefinition<span class="operator">.</span>insertField(<span class="string">&quot;Patronym&quot;</span><span class="operator">,</span> fieldPatronym);

     <span class="comment">// save the updated definition in the manager if supported...</span>
     <span class="keyword">if</span> (m_manager<span class="operator">-</span><span class="operator">&gt;</span>hasFeature(<span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">::</span>MutableDefinitions)) {
         m_definitionSaveRequest<span class="operator">.</span>setManager(m_manager);
         m_definitionSaveRequest<span class="operator">.</span>setContactType(<span class="type"><a href="qcontacttype.html">QContactType</a></span><span class="operator">::</span>TypeContact);
         m_definitionSaveRequest<span class="operator">.</span>setDefinitions(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qcontactdetaildefinition.html">QContactDetailDefinition</a></span><span class="operator">&gt;</span>() <span class="operator">&lt;</span><span class="operator">&lt;</span> nameDefinition);
         m_definitionSaveRequest<span class="operator">.</span>start();
     }</pre>
<p>The equivalent code using the synchronous API looks like:</p>
<pre class="cpp">     <span class="comment">// modify the name definition, adding a patronym field</span>
     <span class="type"><a href="qcontactdetaildefinition.html">QContactDetailDefinition</a></span> nameDefinition <span class="operator">=</span> definitions<span class="operator">.</span>value(<span class="type"><a href="qcontactname.html">QContactName</a></span><span class="operator">::</span>DefinitionName);
     <span class="type"><a href="qcontactdetailfielddefinition.html">QContactDetailFieldDefinition</a></span> fieldPatronym;
     fieldPatronym<span class="operator">.</span>setDataType(<span class="type"><a href="http://qt.nokia.com/doc/4.7/qvariant.html">QVariant</a></span><span class="operator">::</span>String);
     nameDefinition<span class="operator">.</span>insertField(<span class="string">&quot;Patronym&quot;</span><span class="operator">,</span> fieldPatronym);

     <span class="comment">// save the updated definition in the manager if supported...</span>
     <span class="keyword">if</span> (m_manager<span class="operator">.</span>hasFeature(<span class="type"><a href="qcontactmanager.html">QContactManager</a></span><span class="operator">::</span>MutableDefinitions)) {
         m_manager<span class="operator">.</span>saveDetailDefinition(nameDefinition<span class="operator">,</span> <span class="type"><a href="qcontacttype.html">QContactType</a></span><span class="operator">::</span>TypeContact);
     }</pre>
<p>Note that some managers do not support mutable definitions, and hence attempting to modify or remove detail definitions in those managers will fail.</p>
</div>
<!-- @@@contactsusage.html -->
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
  <p>
     <acronym title="Copyright">&copy;</acronym> 2008-2011 Nokia Corporation and/or its
     subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
     in Finland and/or other countries worldwide.</p>
  <p>
     All other trademarks are property of their respective owners. <a title="Privacy Policy"
     href="http://qt.nokia.com/about/privacy-policy">Privacy Policy</a></p>
  <br />
  <p>
    Licensees holding valid Qt Commercial licenses may use this document in accordance with the    Qt Commercial License Agreement provided with the Software or, alternatively, in accordance    with the terms contained in a written agreement between you and Nokia.</p>
  <p>
    Alternatively, this document may be used under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU
    Free Documentation License version 1.3</a>
    as published by the Free Software Foundation.</p>
</div>
</body>
</html>