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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Declarative Service Framework Notes Manager

Files:

Execution

This example requires the example Notes Manager service to be pre-registered in order for the application to obtain the default interface. This can be done by using the service framework command line tool to add the corresponding service XML file:

  • ./servicefw add notesmanagerservice.xml

There are 2 ways to run the example:

  • ./qmlnotes (only method for Symbian)
  • qmlviewer declarative-sfw-notes.qml

The XML files for all example services can be found in the QtMobility build directory under install/bin/xmldata

Explanation

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 tools. See Service Framework Notes Manager for more details.

The QServiceManager and QServiceInterfaceDescriptor API are provided to QML through the use of a plugin-based system that allows users to describe a service as a QML element called Service. The service framework QML plugin also acces to an instance of the service from within QML so that clients can make metacalls on the service object.

This example demonstrates how QML can be used to completely control the logic of the application, using a combination of declarative elements and Javascript code. To run the application refer to the above execution instructions on how to setup and run the example.

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

The section below 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 QtMobility Service Framework QML plugin library which containts the required QML elements:

 import QtMobility.serviceframework 1.1

In most cases we will need the service instance to be available to all parts of the QML file, meaning that we should declare a global variant for the QObject returned from the service instance. It is also good practice to initialise this value to 0.

     property variant notesManager: 0

Now we can initiate our Service element with a default interface name and obtain the service instance to our global object variable in the component on-completion section.

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

         Component.onCompleted: {
             notesManager = notesService.serviceObject;
         }
     }

Although a default instance is obtained, the application allows for manually specifying the Service::interfaceName property of the Service element to check if there was a valid default service at this interface name. Similarly, if there is a valid descriptor then the service instance can be obtained and we can call the initialise code of our notes manager.

             notesService.interfaceName = input;

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

Connecting signals from our service object requires the following code. Note the use of the ignoreUnknownSignals property which removes warnings for connecting unknown signals before QML has obtained its QObject service instance.

     Connections {
         target: notesManager
         ignoreUnknownSignals: true

         onSoundAlarm: {
             alarmDialog.text = "ALERT SOUNDED!!!" + "\n\n" +
                                formatDateTime(alarm) + "\n\n" + notesManager.alarmMessage;
             alarmDialog.opacity = 1;
         }
     }

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

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.

[0]; s.parentNode.insertBefore(ga, s); })();
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 qtmobility-1.1
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