//! [Example of an asynchronous request slot] void AsyncRequestExample::contactFetchRequestStateChanged(QContactAbstractRequest::State newState) { if (newState == QContactAbstractRequest::FinishedState) { QContactFetchRequest *request = qobject_cast<QContactFetchRequest*>(QObject::sender()); if (request->error() != QContactManager::NoError) { qDebug() << "Error" << request->error() << "occurred during fetch request!"; return; } QList<QContact> results = request->contacts(); for (int i = 0; i < results.size(); i++) { qDebug() << "Retrieved contact:" << results.at(i).displayLabel(); } } else if (newState == QContactAbstractRequest::CanceledState) { qDebug() << "Fetch operation canceled!"; } }
/* One of our subrequests has finished. Go to the next step. */ void FetchByIdRequestController::handleFinishedSubRequest(QContactAbstractRequest* subReq) { // It's possibly already finished if this function is called asynchronously and waitForFinished // had previously been called if (isFinished()) return; // For a FetchByIdRequest, we know that the only subrequest is a QContactFetchRequest. // The next step is simply to take the results and reformat it. // Take the results: QContactFetchRequest* qcfr = qobject_cast<QContactFetchRequest*>(subReq); QList<QContact> contacts = qcfr->contacts(); QContactManager::Error error = qcfr->error(); // Build an index into the results QHash<QContactLocalId, QContact> idMap; if (error == QContactManager::NoError) { foreach (const QContact& contact, contacts) { idMap.insert(contact.localId(), contact); }