<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- porting.qdoc --> <title>Porting Applications from QtMobility Sensors to Qt Sensors | 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 >Porting Applications from QtMobility Sensors to Qt Sensors</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="#overview">Overview</a></li> <li class="level1"><a href="#qml">QML</a></li> <li class="level1"><a href="#c">C++</a></li> <li class="level2"><a href="#includes">Includes</a></li> <li class="level2"><a href="#macros-and-namespace">Macros and Namespace</a></li> <li class="level2"><a href="#qtimestamp">qtimestamp</a></li> <li class="level1"><a href="#project-files">Project Files</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Porting Applications from QtMobility Sensors to Qt Sensors</h1> <span class="subtitle"></span> <!-- $$$qtsensors-porting.html-description --> <div class="descr"> <a name="details"></a> <a name="overview"></a> <h2 id="overview">Overview</h2> <p>The initial release of Qt Sensors (5.0) is generally expected to be source compatible with QtMobility Sensors 1.2. This document attempts to explain where things need to be changed in order to port applications to Qt Sensors.</p> <a name="qml"></a> <h2 id="qml">QML</h2> <p>In <code>QtMobility</code>, the C++ classes like <code>QAccelerometer</code> were directly used as QML types. In Qt Sensors, there are now separate classes for the QML types, which have no public C++ API.</p> <p>The new QML types in Qt Sensors fix some issues the former QtMobility QML types had, for example:</p> <ul> <li>The reading types now have proper change notifications.</li> <li><code>availableDataRates</code> and <code>outputRanges</code> of the <code>Sensor</code> type are now proper list types.</li> <li>The <code>identifier</code> and <code>type</code> properties of <code>Sensor</code> can now be used.</li> <li>The <code>lux</code> property of <code>LightSensorReading</code> has been renamed to <code>illuminance</code>.</li> <li>The <code>QmlSensors</code> singleton now allows to query for sensor types.</li> </ul> <p>For more information, see the <a href="qtsensors-qmlmodule.html">QML API</a> documentation.</p> <a name="c"></a> <h2 id="c">C++</h2> <p>The C++ API mainly remained the same as in QtMobility.</p> <a name="includes"></a> <h3 >Includes</h3> <p>QtMobility Sensors installed headers into a <code>Qt</code> Sensors directory. This is also the directory that Qt Sensors uses. It is therefore expected that includes that worked with QtMobility Sensors should continue to work.</p> <p>For example:</p> <pre class="cpp"> <span class="preprocessor">#include <QAccelerometer></span> <span class="preprocessor">#include <qaccelerometer.h></span> <span class="preprocessor">#include <QtSensors/QAccelerometer></span> <span class="preprocessor">#include <QtSensors/qaccelerometer.h></span> </pre> <a name="macros-and-namespace"></a> <h3 >Macros and Namespace</h3> <p>QtMobility Sensors was built in a <code>QtMobility</code> namespace. This was enabled by the use of various macros. Qt Sensors does not normally build into a namespace and the macros from QtMobility no longer exist.</p> <ul> <li>QTM_BEGIN_NAMESPACE</li> <li>QTM_END_NAMESPACE</li> <li>QTM_USE_NAMESPACE</li> <li>QTM_PREPEND_NAMESPACE(x)</li> </ul> <p>Note that Qt can be configured to build into a namespace. If Qt is built in this way then Qt Sensors is also built into the nominated namespace. However, as this is optional, the macros for this are typically defined to do nothing.</p> <ul> <li>QT_BEGIN_NAMESPACE</li> <li>QT_END_NAMESPACE</li> <li>QT_USE_NAMESPACE</li> <li>QT_PREPEND_NAMESPACE(x)</li> </ul> <a name="qtimestamp"></a> <h3 >qtimestamp</h3> <p>qtimestamp was previously defined as an opaque type equivalent to a quint64. It existed as a class due to an implementation detail.</p> <p>In Qt Sensors, the API uses quint64 instead of qtimestamp. qtimestamp still exists as a typedef so that applications that refer to qtimestamp can be compiled.</p> <a name="project-files"></a> <h2 id="project-files">Project Files</h2> <p>QtMobility Sensors applications used this in their project files to enable the Sensors API.</p> <pre class="cpp"> CONFIG <span class="operator">+</span><span class="operator">=</span> mobility MOBILITY <span class="operator">+</span><span class="operator">=</span> sensors </pre> <p>Applications should remove these lines and instead use the following statement to enable the Qt Sensors API:</p> <pre class="cpp"> QT <span class="operator">+</span><span class="operator">=</span> sensors </pre> </div> <!-- @@@qtsensors-porting.html --> </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>