Sophie

Sophie

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

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" />
<!-- poster.qdoc -->
  <title>QML Poster 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 Poster 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="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#applying-ndef-filters">Applying NDEF Filters</a></li>
<li class="level1"><a href="#processing-found-ndef-messages">Processing Found NDEF Messages</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QML Poster Example</h1>
<span class="subtitle"></span>
<!-- $$$poster-brief -->
<p>A QML example about reading and displaying NFC Data Exchange Format (NDEF) messages.</p>
<!-- @@@poster -->
<!-- $$$poster-description -->
<div class="descr"> <a name="details"></a>
<p>The QML Poster example displays the contents of specifically formatted NFC Data Exchange Format (NDEF) messages read from an NFC Tag. The NDEF message must contain a URI record, an optional <code>image/*</code> MIME record, and one or more localized Text records.</p>
<p class="centerAlign"><img src="images/qml-poster-example.png" alt="" /></p><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>
<a name="applying-ndef-filters"></a>
<h2 id="applying-ndef-filters">Applying NDEF Filters</h2>
<p>The example is designed to display the content of a very specific type of NFC tag. The tag must contain at least one URI record and one text record. If those two record types do not exist, nothing will happen. Such filtering is applied via the <a href="qml-qtnfc-nearfield.html">NearField</a> type's filter property. The property accepts a list of <a href="qml-qtnfc-ndeffilter.html">NdefFilter</a> objects.</p>
<pre class="qml">

  filter: [
      NdefFilter { type: "U"; typeNameFormat: NdefRecord.NfcRtd; maximum: 1 },
      NdefFilter { type: "T"; typeNameFormat: NdefRecord.NfcRtd },
      NdefFilter { typeNameFormat: NdefRecord.Mime; minimum: 0; maximum: 1 }
  ]

</pre>
<a name="processing-found-ndef-messages"></a>
<h2 id="processing-found-ndef-messages">Processing Found NDEF Messages</h2>
<p>Once an appropriate tag is found, the <a href="qml-qtnfc-nearfield.html#messageRecords-prop">NearField::messageRecords</a> property reflects the content. It transports the list of found NDEF records. The QML snippet below demonstrates how these records can be accessed:</p>
<pre class="qml">

  onMessageRecordsChanged: {
      for (i = 0; i < messageRecords.length; ++i) {
          switch (messageRecords[i].typeNameFormat) {
          case NdefRecord.NfcRtd:
              if (messageRecords[i].type === "T") {
                  if (messageRecords[i].localeMatch > currentLocaleMatch) {
                      currentLocaleMatch = messageRecords[i].localeMatch;
                      posterText.text = messageRecords[i].text;
                      found = true;
                  }

              } else if (messageRecords[i].type === "U") {
                   posterUrl.text = messageRecords[i].uri;
                  found = true;
              }
              break;
          case NdefRecord.Mime:
              if (messageRecords[i].type.indexOf("image/") === 0 ) {
                  posterImage.source = messageRecords[i].uri;
                  found = true;
              }
              break;
          }

          if (!found)
              console.warn("Unknown NFC tag detected. Cannot display content.")
      }
  }

</pre>
<p>Files:</p>
<ul>
<li><a href="qtnfc-poster-poster-pro.html">poster/poster.pro</a></li>
<li><a href="qtnfc-poster-poster-qml.html">poster/poster.qml</a></li>
<li><a href="qtnfc-poster-poster-qrc.html">poster/poster.qrc</a></li>
<li><a href="qtnfc-poster-qmlposter-cpp.html">poster/qmlposter.cpp</a></li>
</ul>
</div>
<p><b>See also </b><a href="qtnfc-index.html">Qt NFC</a>.</p>
<!-- @@@poster -->
        </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>