From 5e8994a4fa83f4c2795978f8b9ae893cefc69160 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 2 Jun 2016 13:56:50 +0200 Subject: Make it more obvious what tags the NFC poster example expects. Task-number: QTBUG-53616 Change-Id: Ie3a87abc61100ac8fe0a5b671725f54ae28e1501 Reviewed-by: Martin Smith Reviewed-by: Leena Miettinen --- .../nfc/poster/doc/images/qml-poster-example.png | Bin 5110 -> 7946 bytes examples/nfc/poster/doc/src/poster.qdoc | 21 ++++++++++++++++++++- examples/nfc/poster/poster.qml | 14 +++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/nfc/poster/doc/images/qml-poster-example.png b/examples/nfc/poster/doc/images/qml-poster-example.png index d3ead72e..8ed2292c 100644 Binary files a/examples/nfc/poster/doc/images/qml-poster-example.png and b/examples/nfc/poster/doc/images/qml-poster-example.png differ diff --git a/examples/nfc/poster/doc/src/poster.qdoc b/examples/nfc/poster/doc/src/poster.qdoc index a569f47a..26320f56 100644 --- a/examples/nfc/poster/doc/src/poster.qdoc +++ b/examples/nfc/poster/doc/src/poster.qdoc @@ -31,7 +31,7 @@ \brief A QML example about reading and displaying NFC Data Exchange Format (NDEF) messages. The QML Poster example displays the contents of specifically formatted NFC Data -Exchange Format (NDEF) messages read from an NFC Tag. The NDEF message should +Exchange Format (NDEF) messages read from an NFC Tag. The NDEF message must contain a URI record, an optional \c image/* MIME record, and one or more localized Text records. @@ -39,5 +39,24 @@ localized Text records. \include examples-run.qdocinc +\section1 Applying NDEF Filters + +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 +\l NearField type's filter property. The property accepts a list of \l NdefFilter objects. + +\snippet poster/poster.qml QML NDEF filtering + +\section1 Processing Found NDEF Messages + +Once an appropriate tag is found, the \l NearField::messageRecords property reflects the content. +It transports the list of found NDEF records. The QML snippet below +demonstrates how these records can be accessed: + +\snippet poster/poster.qml messageRecordsChanged 1 +\snippet poster/poster.qml messageRecordsChanged 2 +\snippet poster/poster.qml messageRecordsChanged 3 + \sa {Qt NFC} */ diff --git a/examples/nfc/poster/poster.qml b/examples/nfc/poster/poster.qml index a70a998b..d57ed5d9 100644 --- a/examples/nfc/poster/poster.qml +++ b/examples/nfc/poster/poster.qml @@ -62,13 +62,18 @@ Rectangle { } } + //! [QML NDEF filtering] filter: [ NdefFilter { type: "U"; typeNameFormat: NdefRecord.NfcRtd; maximum: 1 }, NdefFilter { type: "T"; typeNameFormat: NdefRecord.NfcRtd }, NdefFilter { typeNameFormat: NdefRecord.Mime; minimum: 0; maximum: 1 } ] + //! [QML NDEF filtering] + + //! [messageRecordsChanged 1] onMessageRecordsChanged: { + //! [messageRecordsChanged 1] posterText.text = ""; posterImage.source = ""; posterUrl.text = ""; @@ -76,6 +81,7 @@ Rectangle { var currentLocaleMatch = NdefTextRecord.LocaleMatchedNone; var i; var found = false; + //! [messageRecordsChanged 2] for (i = 0; i < messageRecords.length; ++i) { switch (messageRecords[i].typeNameFormat) { case NdefRecord.NfcRtd: @@ -102,18 +108,24 @@ Rectangle { if (!found) console.warn("Unknown NFC tag detected. Cannot display content.") } + //! [messageRecordsChanged 2] root.state = "show"; + //! [messageRecordsChanged 3] } + //! [messageRecordsChanged 3] } Text { id: touchText anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - text: "Touch an NFC tag" + text: "Touch an NFC tag with at least one Text and one URI record." font.bold: true font.pointSize: 18 + wrapMode: Text.WordWrap + width: root.width*0.75 + horizontalAlignment: Text.AlignHCenter } Image { -- cgit v1.2.3