Home · All Classes · All Functions ·

Versit API

Namespace

The QtMobility APIs are placed into the QtMobility namespace. This is done to facilitate the future migration of Mobility APIs into Qt. See the Quickstart guide for an example on how the namespace impacts on application development.

Overview

Versit API provides a set of methods to parse/read (QVersitReader) and encode/write (QVersitWriter) Versit ® documents such as vCards (http://www.imc.org/pdi/). Currently QVersitReader and QVersitWriter support reading and writing vCard 2.1 and 3.0 formats.

Versit API also provides utilities to import (QVersitContactImporter) QContacts from Versit documents and export (QVersitContactExporter) QContacts to Versit documents.

Versit ® is a trademark of the Internet Mail Consortium.

Usage

        // Create the input vCard
        QBuffer input;
        input.open(QBuffer::ReadWrite);
        QByteArray inputVCard =
            "BEGIN:VCARD\r\nVERSION:2.1\r\nFN:John Citizen\r\nN:Citizen;John;Q;;\r\nEND:VCARD\r\n";
        input.write(inputVCard);
        input.seek(0);

        // Parse the input into QVersitDocuments
        // Note: we could also use the more convenient QVersitReader(QByteArray) constructor.
        QVersitReader reader;
        reader.setDevice(&input);
        reader.startReading(); // Remember to check the return value
        reader.waitForFinished();

        // Convert the QVersitDocuments to QContacts
        QList<QVersitDocument> inputDocuments = reader.results();
        QVersitContactImporter importer;
        if (!importer.importDocuments(inputDocuments))
            return;
        QList<QContact> contacts = importer.contacts();
        // Note that the QContacts are not saved yet.
        // Use QContactManager::saveContacts() for saving if necessary

        // Export the QContacts back to QVersitDocuments
        QVersitContactExporter exporter;
        if (!exporter.exportContacts(contacts, QVersitDocument::VCard30Type))
            return;
        QList<QVersitDocument> outputDocuments = exporter.documents();

        // Encode the QVersitDocument back to a vCard
        // Note: we could also use the more convenient QVersitWriter(QByteArray*) constructor.
        QBuffer output;
        output.open(QBuffer::ReadWrite);
        QVersitWriter writer;
        writer.setDevice(&output);
        writer.startWriting(outputDocuments); // Remember to check the return value
        writer.waitForFinished();

        // Read the vCard back to a QByteArray
        output.seek(0);
        QByteArray outputVCard(output.readAll());

Main Classes


Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Mobility Project 1.0.1