Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Contacts Asynchronous API

Introduction

The Contacts Asynchronous API enables a client to asynchronously fetch, update, or remove contact and relationship data from a contact manager. Use of the asynchronous API offers the programmer greater flexibility when requesting information from remote or slow local datastores.

Using the API

The asynchronous API offered by the Contacts module is available through classes derived from the QContactAbstractRequest class. It consists of two major sections:

  • Contact Manipulation
  • Relationship Manipulation

The functionality offered by the synchronous API in these two categories is also available through the asynchronous API. There is one category of functionality which is not provided by the asynchronous API which is provided by the synchronous API: some information and reporting functionality is only provided through the synchronous API.

For detailed information about the information and reporting functionality provided, please refer to the documentation for the Contacts Synchronous API.

The functions to set and retrieve the id of the self-contact are also only provided by the synchronous API.

Contact Manipulation

The most common type of operation that clients will perform involves retrieval or modification of contacts. For in-depth information about contact manipulation, please refer to the Contacts Synchronous API.

There are four different types of operation which are supported by the asynchronous API:

  • Fetch contact ids
  • Fetch contacts
  • Save contacts (create or update)
  • Remove contacts

These operations are supported via the QContactIdFetchRequest, QContactFetchRequest, QContactSaveRequest and QContactRemoveRequest classes, respectively.

The synchronous API offered by the QContactManager class to allow manipulation of contacts consists of the following functions:

Relationship Manipulation

Contacts may be related in various ways. The contacts API allows clients to define relationships between contacts. For in-depth information about relationship manipulation, please refer to the Contacts Synchronous API. Support for relationships is backend specific. There are three different types of operation which are supported by the asynchronous API:

  • Fetch relationships
  • Save relationships (create or update, if supported by the backend)
  • Remove relationships (if supported by the backend)

These operations are supported via the QContactRelationshipFetchRequest, QContactRelationshipSaveRequest and QContactRelationshipRemoveRequest classes respectively.

The synchronous API offered by the QContactManager class to allow manipulation of relationships consists of the following functions:

Examples Of Usage

Fetching Contacts

The client sets up a request for contacts matching a specific criteria from a particular manager.

Results from the request will be displayed to the user as they are received.

 void RequestExample::performRequest()
 {
     // retrieve any contact whose first name is "Alice"
     QContactDetailFilter dfil;
     dfil.setDetailType(QContactName::Type, QContactName::FieldFirstName);
     dfil.setValue("Alice");
     dfil.setMatchFlags(QContactFilter::MatchExactly);

     // m_fetchRequest was created with m_fetchRequest = new QContactFetchRequest() in the ctor.
     m_fetchRequest->setManager(this->m_manager); // m_manager is a QContactManager*.
     m_fetchRequest->setFilter(dfil);
     connect(m_fetchRequest, SIGNAL(resultsAvailable()), this, SLOT(printContacts()));
     connect(m_fetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
             this, SLOT(stateChanged(QContactAbstractRequest::State)));
     if (!m_fetchRequest->start()) {
         qDebug() << "Unable to request contacts!";
         QCoreApplication::exit(0);
     } else {
         qDebug() << "Requested contacts; awaiting results...";
     }
 }

 void RequestExample::printContacts()
 {
     QList<QContact> results = m_fetchRequest->contacts();
     for (m_previousLastIndex = 0; m_previousLastIndex < results.size(); ++m_previousLastIndex) {
         qDebug() << "Found an Alice:" << results.at(m_previousLastIndex).displayLabel();
     }
 }

 void RequestExample::stateChanged(QContactAbstractRequest::State state)
 {
     // once we've finished retrieving results, stop processing events.
     if (state == QContactAbstractRequest::FinishedState
         || state == QContactAbstractRequest::CanceledState) {
         qDebug() << "Finished displaying asynchronously retrieved contacts!";
         QCoreApplication::exit(0);
     }
 }

Other Asynchronous Operations

All other asynchronous operations are performed in a similar manner to the previous example. A request of the desired type (which is derived from QContactAbstractRequest) is created, certain criteria are set which determine the intent of the request, and the signals of the request are connected to slots which deals with the results. The request can then be started.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web