Home · All Classes · All Functions ·

Declarative Service Framework Notes Manager

Files:

This example demonstrates how to use the Notes Manager service plugin to implement a notes managing application with QML as the declarative user-interface. There is also a non-QML counterpart which demonstrates an identical application using standard Qt user-interface tool. See Service Framework Notes Manager for more details.

Explanation

In general, QML requires external types and registrations to be provided via a plugin-based system, which the service framework does not currently provide. Instead, we have a wrapper class which provides access to the QServiceManager and QServiceInterfaceDescriptor API that needs to be included in the project and declared in the main funciton of the application. The wrapper is referred to as QDeclarativeService.

This example demonstrates how QML can be used to completely control the logic of the application, using a combination of declarative elements and Javascript in the QML file. The main function is used to produce an application binary but once service framework supports a QML plugin, only the QML file will be needed. Also contained is a class that registers our Notes Manager service to supply the plugin library, which can also be done using the servicefw tool.

There is another service framework example that demonstrates how to use the wrapper to browse a list of services to select for dialing usage. See Declarative Service Framework Dialer for a detailed explanation.

The secion belows explains how QML can be used to emulate to exact functionality of the alternate Qt/C++ example.

QML File

The very first step is to import our registered types with the following:

    import QtMobility.serviceframework 1.0

Now to obtain the default service with a specific interface name from within QML we can use the Service wrapper item as follows:

        Service {
            id: notesService
            interfaceName: "com.nokia.qt.examples.NotesManager"
        }

In most cases we will need the service to be avaiable to all parts of the QML file, meaning the actual QObject returned from the service wrapper needs to be a global property.

        property var notesManager: notesService.serviceObject

The interfaceName property of the Service item has READ and WRITE methods which can be used to obtain a new service instance and check if there was a valid default service.

                notesService.interfaceName = input;

                if (notesService.valid) {
                    notesManager = notesService.serviceObject;

With a valid reference which points to the service plugin class we can now invoke methods directly from the Notes Manager plugin. The example below shows how to obtain a list of notes and delete one from the notes manager database through QML.

                var list = notesManager.noteSet;
                notesManager.removeNote(list[curr-1].index);

The Notes Manager plugin also provides readable functions which return the values of a single note and can be utilized to display on the UI as follows:

            notesManager.setSearch(searchText);
            var list = notesManager.noteSet;
            size = list.length;

            if (size > 0) {
                noteLabel.text = list[curr-1].message;
                datetimeLabel.text = formatDateTime(list[curr-1].alarm);
            }


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