Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 50facae208d4a6f280e44a513b104320 > files > 1412

qt-mobility-doc-1.2.0-13.mga5.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qml-publishsubscribe.qdoc -->
  <title>Qt Mobility 1.2: Publish and Subscribe QML Plugin</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>QtMobility Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li>Publish and Subscribe QML Plugin</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#overview">Overview</a></li>
<li class="level2"><a href="#publisher">Publisher</a></li>
<li class="level2"><a href="#subscriber">Subscriber</a></li>
<li class="level1"><a href="#examples">Examples</a></li>
<li class="level1"><a href="#qml-elements">QML Elements</a></li>
</ul>
</div>
<h1 class="title">Publish and Subscribe QML Plugin</h1>
<span class="subtitle"></span>
<!-- $$$qml-publishsubscribe.html-description -->
<div class="descr"> <a name="details"></a>
<a name="overview"></a>
<h2>Overview</h2>
<p>The Publish and Subscribe QML API enables QML applications to access values stored in the Value Space from QML. The publish/subscribe features therefore allow an easy to use form of IPC.</p>
<a name="publisher"></a>
<h3>Publisher</h3>
<p>The <a href="qml-valuespacepublisher.html">ValueSpacePublisher</a> element allows us to publish key-value pairs of data to a known path. The path has the form of a directory structure path with the keys acting as files at the end of the path. The process is that the developer declares a <a href="qml-valuespacepublisher.html">ValueSpacePublisher</a> element and then with a given path defines a list of keys. For example</p>
<pre class="qml"> <span class="type"><a href="qml-valuespacepublisher.html">ValueSpacePublisher</a></span> {
     <span class="name">id</span>: <span class="name">battery</span>
     <span class="name">path</span>: <span class="string">&quot;/power/battery&quot;</span>
     <span class="name">keys</span>: [<span class="string">&quot;charge&quot;</span>, <span class="string">&quot;charging&quot;</span>]
 }</pre>
<p>To publish a value the key need only be set to the value. Here we see that the key is expressed as the last name in the path with dot notation followed by the key name.</p>
<pre class="qml">     battery.charge = 50
     battery.charging = true</pre>
<a name="subscriber"></a>
<h3>Subscriber</h3>
<p>The <a href="qml-valuespacesubscriber.html">ValueSpaceSubscriber</a> element also defines the path to the key/value. For each <i>key</i> a different <a href="qml-valuespacesubscriber.html">ValueSpaceSubscriber</a> needs to be declared. In the above example using the keys 'charge' and 'charging' we will need subscribers for each one</p>
<pre class="qml"> <span class="type"><a href="qml-valuespacesubscriber.html">ValueSpaceSubscriber</a></span> {
     <span class="name">id</span>: <span class="name">batteryCharge</span>
     <span class="name">path</span>: <span class="string">&quot;/power/battery/charge&quot;</span>
 }
 <span class="type"><a href="qml-valuespacesubscriber.html">ValueSpaceSubscriber</a></span> {
     <span class="name">id</span>: <span class="name">batteryCharging</span>
     <span class="name">path</span>: <span class="string">&quot;/power/battery/charging&quot;</span>
 }</pre>
<p>Now the values being published can be read and used</p>
<pre class="qml"> <span class="type"><a href="http://qt.nokia.com/doc/4.7/qml-state.html">State</a></span> {
     <span class="name">name</span>: <span class="string">&quot;low&quot;</span>
     <span class="name">when</span>: <span class="name">batteryCharge</span>.<span class="name">value</span> <span class="operator">&lt;</span> <span class="number">25</span> <span class="operator">&amp;&amp;</span> !<span class="name">batteryCharging</span>.<span class="name">value</span>
     <span class="type"><a href="http://qt.nokia.com/doc/4.7/qml-propertychanges.html">PropertyChanges</a></span> {
         <span class="name">target</span>: <span class="name">visualCharge</span>
         <span class="name">color</span>: <span class="string">&quot;red&quot;</span>
     }
 }</pre>
<a name="examples"></a>
<h2>Examples</h2>
<ul>
<li><a href="battery-charge.html">Accessing Publish and Subscribe from QML</a></li>
</ul>
<a name="qml-elements"></a>
<h2>QML Elements</h2>
<table class="annotated">
<tr class="odd topAlign"><td class="tblName"><p><a href="qml-valuespacepublisher.html">QML ValueSpacePublisher Element</a></p></td><td class="tblDescr"><p>The ValueSpacePublisher element represents a path in the value space where keys can be published.</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qml-valuespacesubscriber.html">QML ValueSpaceSubscriber Element</a></p></td><td class="tblDescr"><p>The QValueSpaceSubscriber class allows applications to read and subscribe to Value Space paths.</p></td></tr>
</table>
</div>
<!-- @@@qml-publishsubscribe.html -->
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
  <p>
     <acronym title="Copyright">&copy;</acronym> 2008-2011 Nokia Corporation and/or its
     subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
     in Finland and/or other countries worldwide.</p>
  <p>
     All other trademarks are property of their respective owners. <a title="Privacy Policy"
     href="http://qt.nokia.com/about/privacy-policy">Privacy Policy</a></p>
  <br />
  <p>
    Licensees holding valid Qt Commercial licenses may use this document in accordance with the    Qt Commercial License Agreement provided with the Software or, alternatively, in accordance    with the terms contained in a written agreement between you and Nokia.</p>
  <p>
    Alternatively, this document may be used under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU
    Free Documentation License version 1.3</a>
    as published by the Free Software Foundation.</p>
</div>
</body>
</html>