<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- sensor_explorer.qdoc --> <title>Qt Sensors - Explorer QML Example | Qt Sensors 5.9</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.9</td><td ><a href="qtsensors-index.html">Qt Sensors</a></td><td ><a href="qtsensors-examples.html">Qt Sensors Examples</a></td><td >Qt Sensors - Explorer QML Example</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#sensor-explorer-qml-import">Sensor Explorer QML Import</a></li> <li class="level1"><a href="#sensor-explorer-qml-application">Sensor Explorer QML Application</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Qt Sensors - Explorer QML Example</h1> <span class="subtitle"></span> <!-- $$$sensor_explorer-description --> <div class="descr"> <a name="details"></a> <p class="centerAlign"><img src="images/qtsensors-examples-explorer.png" alt="" /></p><p>This example is divided into two parts:</p> <ul> <li>A <a href="qtsensors-sensor-explorer-example.html#sensor-explorer-qml-import">C++ plugin</a> that provides QML alternatives for <code>QSensorExplorer</code>, <code>QPropertyInfo</code> and <code>QSensorItem</code> C++ classes.</li> <li>A <a href="qtsensors-sensor-explorer-example.html#sensor-explorer-qml-application">QML Application</a> that uses the QML types to read the sensor meta-data and present it.</li> </ul> <p>This example is built as an executable with C++ code that runs the QML, but it can also be launched directly using the <code>qmlscene</code> tool. You should build the top-level <i>sensor_explorer</i> project before trying to run this example or it will not be able to find its dependencies.</p> <pre class="cpp"> qmlscene <span class="operator">-</span>I <span class="operator">.</span> sensor_explorer<span class="operator">.</span>qml </pre> <p>Above, the -I . parameter adds the current directory as a module import path to locate the Explorer QML module.</p> <a name="sensor-explorer-qml-import"></a> <h2 id="sensor-explorer-qml-import">Sensor Explorer QML Import</h2> <p>The Sensor Explorer QML import defines the <i>Explorer</i> QML module, exporting <code>QSensorExplorer</code>, <code>QPropertyInfo</code> and <code>QSensorItem</code> C++ classes as QML types. The source code is available in the <code>sensor_explorer/import</code> subdirectory.</p> <a name="sensor-explorer-qml-application"></a> <h2 id="sensor-explorer-qml-application">Sensor Explorer QML Application</h2> <p>To write a QML application that will use the QML types exposed by the Explorer module, following steps are needed:</p> <p>Import the Explorer 1.0 declarative plugin:</p> <pre class="qml"> import Explorer 1.0 </pre> <p>Create a SensorExplorer QML item:</p> <pre class="qml"> <span class="type">SensorExplorer</span> { <span class="name">id</span>: <span class="name">explorer</span> } </pre> <p>You can retrieve a list of all available sensors using <code>SensorExplorer.availableSensors</code>:</p> <pre class="qml"> <span class="name">model</span>: <span class="name">explorer</span>.<span class="name">availableSensors</span> </pre> <p>The example uses the returned list as a model to populate a view of available sensors.</p> <p>To retrieve the properties of a sensor, use <code>SensorItem.properties</code>:</p> <pre class="qml"> <span class="name">propertyList</span>.<span class="name">model</span> <span class="operator">=</span> <span class="name">explorer</span>.<span class="name">selectedSensorItem</span>.<span class="name">properties</span> </pre> <p>The property list is used as a model for another view that displays the property names and values.</p> <p>It is possible to edit the values of certain sensor properties. Selecting a writable property value will open an editor. <code>SensorExplorer</code> QML type allows you to pass a new value for a sensor property value as follows:</p> <pre class="qml"> <span class="name">explorer</span>.<span class="name">selectedSensorItem</span>.<span class="name">changePropertyValue</span>(<span class="name">propertyList</span>.<span class="name">selectedItem</span>, <span class="name">loaderEditor</span>.<span class="name">item</span>.<span class="name">text</span>); </pre> <p>Starting and stopping a sensor can be done by setting the <code>SensorItem.start</code> property:</p> <pre class="qml"> <span class="keyword">if</span> (<span class="name">text</span> <span class="operator">===</span> <span class="string">"Start"</span>) { <span class="name">explorer</span>.<span class="name">selectedSensorItem</span>.<span class="name">start</span> <span class="operator">=</span> <span class="number">true</span>; <span class="name">text</span> <span class="operator">=</span> <span class="string">"Stop"</span>; } <span class="keyword">else</span> { <span class="name">explorer</span>.<span class="name">selectedSensorItem</span>.<span class="name">start</span> <span class="operator">=</span> <span class="number">false</span>; <span class="name">text</span> <span class="operator">=</span> <span class="string">"Start"</span>; } </pre> <p>Files:</p> <ul> <li><a href="qtsensors-sensor-explorer-makefile-qml.html">sensor_explorer/Makefile.qml</a></li> <li><a href="qtsensors-sensor-explorer-sensor-explorer-qml.html">sensor_explorer/sensor_explorer.qml</a></li> <li><a href="qtsensors-sensor-explorer-import-explorer-cpp.html">sensor_explorer/import/explorer.cpp</a></li> <li><a href="qtsensors-sensor-explorer-import-explorer-h.html">sensor_explorer/import/explorer.h</a></li> <li><a href="qtsensors-sensor-explorer-import-propertyinfo-cpp.html">sensor_explorer/import/propertyinfo.cpp</a></li> <li><a href="qtsensors-sensor-explorer-import-propertyinfo-h.html">sensor_explorer/import/propertyinfo.h</a></li> <li><a href="qtsensors-sensor-explorer-import-sensoritem-cpp.html">sensor_explorer/import/sensoritem.cpp</a></li> <li><a href="qtsensors-sensor-explorer-import-sensoritem-h.html">sensor_explorer/import/sensoritem.h</a></li> <li><a href="qtsensors-sensor-explorer-main-cpp.html">sensor_explorer/main.cpp</a></li> <li><a href="qtsensors-sensor-explorer-qml-pro.html">sensor_explorer/qml.pro</a></li> <li><a href="qtsensors-sensor-explorer-qml-qrc.html">sensor_explorer/qml.qrc</a></li> <li><a href="qtsensors-sensor-explorer-sensor-explorer-pro.html">sensor_explorer/sensor_explorer.pro</a></li> <li><a href="qtsensors-sensor-explorer-explorer-qmldir.html">sensor_explorer/Explorer/qmldir</a></li> <li><a href="qtsensors-sensor-explorer-import-import-pro.html">sensor_explorer/import/import.pro</a></li> <li><a href="qtsensors-sensor-explorer-import-qmldir.html">sensor_explorer/import/qmldir</a></li> </ul> </div> <!-- @@@sensor_explorer --> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br> The documentation provided herein is licensed 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.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>