Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > 814a2b4c48f3ef6444b2ff5bf854d05a > files > 334

qtconnectivity5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- corkboard.qdoc -->
  <title>QML CorkBoard Example | Qt NFC 5.12.6</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.12</td><td ><a href="qtnfc-index.html">Qt NFC</a></td><td >QML CorkBoard Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtnfc-index.html">Qt 5.12.6 Reference Documentation</a></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="#implementation-details">Implementation details</a></li>
<li class="level1"><a href="#corkboards-qml-details">corkboards.qml details</a></li>
<li class="level1"><a href="#mode-qml-details">Mode.qml details</a></li>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QML CorkBoard Example</h1>
<span class="subtitle"></span>
<!-- $$$corkboard-brief -->
<p>A QML example about displaying NFC Data Exchange Format (NDEF) messages.</p>
<!-- @@@corkboard -->
<!-- $$$corkboard-description -->
<div class="descr"> <a name="details"></a>
<p>The QML corkboard example displays the contents of NDEF messages read from an NFC Tag. Each newly detected NDEF message is added to the corkboard and can be dragged into an arbitrary position on the board. The corkboard has a <i>Personal</i> and <i>Work</i> space. The workspace can be changed by sliding left or right.</p>
<p class="centerAlign"><img src="images/corkboard.png" alt="" /></p><a name="implementation-details"></a>
<h2 id="implementation-details">Implementation details</h2>
<p>In the corkboard example, we use the following .qml files:</p>
<ul>
<li>corkboards.qml</li>
<li>Mode.qml</li>
</ul>
<p>The main.cpp holds the application logic to load the main view stored in the corkboards.qml file.</p>
<pre class="cpp">

  <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
  {
      <span class="type">QGuiApplication</span> application(argc<span class="operator">,</span> argv);
      <span class="type">QQuickView</span> view;
      view<span class="operator">.</span>setSource(<span class="type">QUrl</span>(<span class="string">&quot;qrc:/corkboards.qml&quot;</span>));
      view<span class="operator">.</span>setResizeMode(<span class="type">QQuickView</span><span class="operator">::</span>SizeRootObjectToView);
      view<span class="operator">.</span>show();
      <span class="keyword">return</span> application<span class="operator">.</span>exec();
  }

</pre>
<a name="corkboards-qml-details"></a>
<h2 id="corkboards-qml-details">corkboards.qml details</h2>
<p>There are two basic QML components in this file:</p>
<ul>
<li><a href="qml-qtnfc-nearfield.html">NearField</a></li>
<li>ListView</li>
</ul>
<p>The first time the <a href="qml-qtnfc-nearfield.html">NearField</a> QML type is instantiated, the Component.onCompleted handler will start the NFC polling process. The <a href="qml-qtnfc-nearfield.html">onMessageRecordsChanged</a> handler parses NFC Messages that are detected by the <a href="qml-qtnfc-nearfield.html">NearField</a> component and builds up a data model that is passed into the ListView. Additionally, every time the <a href="qml-qtnfc-nearfield.html">NearField</a> manager stops the polling process, the onPollingChanged handler restarts it.</p>
<pre class="cpp">

      NearField {
          property bool requiresManualPolling: false
          orderMatch: false

          onMessageRecordsChanged: {
          ...
          onPollingChanged: {
          ...
          Component.onCompleted: {
          ...
          }

</pre>
<p>The ListView component takes a ListModel as parameter (built from the NFC records). The view of each of the items of the model is defined by the Mode component (its implementation details can be found in the file Mode.qml). The data model consists of a list of corkboards. Each corkboard can display multiple NFC text message records.</p>
<pre class="cpp">

      ListView {
          id: listView
          ...
          model: list
          ...
          delegate: Mode {}
      }

</pre>
<a name="mode-qml-details"></a>
<h2 id="mode-qml-details">Mode.qml details</h2>
<p>A corkboard title is displayed for each of the items that form part of the data model:</p>
<pre class="cpp">

          Text {
              anchors { horizontalCenter: parent.horizontalCenter; top: parent.top; topMargin: 10}
              text: name;
              font { pixelSize: 30; bold: true }

</pre>
<p>Every text record that was read from an NFC message, is represented by a sticky note with its own position on the display. Initially the position is set randomly. The text on the sticky note is set on a TextField.</p>
<pre class="cpp">

          Repeater {
              model: notes
              Item {
                  id: stickyPage

                  x: ListView.width * (0.7 * Math.random() + 0.1)
                  y: ListView.height * (0.7 * Math.random() + 0.1)
                  ...
                  Item {
                      id: sticky
                      ...
                      TextEdit {
                          id: myText
                          text: noteText
                          ...
                      }
                      ...

</pre>
<a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<p>Files:</p>
<ul>
<li><a href="qtnfc-corkboard-mode-qml.html">corkboard/Mode.qml</a></li>
<li><a href="qtnfc-corkboard-android-androidmanifest-xml.html">corkboard/android/AndroidManifest.xml</a></li>
<li><a href="qtnfc-corkboard-corkboard-pro.html">corkboard/corkboard.pro</a></li>
<li><a href="qtnfc-corkboard-corkboard-qrc.html">corkboard/corkboard.qrc</a></li>
<li><a href="qtnfc-corkboard-corkboards-qml.html">corkboard/corkboards.qml</a></li>
<li><a href="qtnfc-corkboard-main-cpp.html">corkboard/main.cpp</a></li>
</ul>
<p>Images:</p>
<ul>
<li><a href="images/used-in-examples/corkboard/NfcFlag.png">corkboard/NfcFlag.png</a></li>
<li><a href="images/used-in-examples/corkboard/cork.jpg">corkboard/cork.jpg</a></li>
<li><a href="images/used-in-examples/corkboard/icon.png">corkboard/icon.png</a></li>
<li><a href="images/used-in-examples/corkboard/note-yellow.png">corkboard/note-yellow.png</a></li>
<li><a href="images/used-in-examples/corkboard/tack.png">corkboard/tack.png</a></li>
</ul>
</div>
<p><b>See also </b><a href="qtnfc-index.html">Qt NFC</a>.</p>
<!-- @@@corkboard -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 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>