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

The Versit API provides a library to convert QContacts to and from vCard files.

vCards are represented abstract form with the QVersitDocument class. vCard files can be parsed into QVersitDocument form using QVersitReader. QVersitDocument objects can be written to an I/O device using QVersitWriter.

QVersitDocuments can be converted to QContacts using QVersitContactImporter. QContacts can be converted to QVersitDocuments using QVersitContactExporter.

Currently QVersitReader and QVersitWriter support reading and writing vCard 2.1 and vCard 3.0 format documents.

Versit ® is a trademark of the Internet Mail Consortium.

Usage

The following example goes through the process of reading a vCard and importing it to QContact format, then exporting and writing it back out.

First, let's create some data to read. In this case, we create a QBuffer as a demonstration, but any QIODevice will work.

        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);

QVersitReader can be used to parse a vCard or iCalendar from an I/O device to produce a list of 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();
        QList<QVersitDocument> inputDocuments = reader.results();

QVersitDocuments aren't very useful to the QtContacts API. They need to be imported using the QVersitContactImporter.

        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

Conversely, QVersitContactExporter can be used to convert from QContacts to QVersitDocuments.

        QVersitContactExporter exporter;
        if (!exporter.exportContacts(contacts, QVersitDocument::VCard30Type))
            return;
        QList<QVersitDocument> outputDocuments = exporter.documents();

To complete the exporting process, QVersitWriter can be used to write to an I/O device.

        // 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();
        // output.buffer() now contains a vCard

Main Classes

Supported Features

Please see the Supported vCard Features document for a list of vCard features that the Versit module supports.


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