QtMobility Reference Documentation

QML Poster Example

Files:

The QML Poster example displays the contents of specifically formated NDEF messages read from an NFC Tag. The NDEF message should contain a URI record, an optional image/* MIME record and one or more localized Text records.

An NFC enabled poster can be a poster in a public place with an embedded NFC tag. A passerby may stop, read the text printed on the poster and become curious. She sees that the poster contains an NFC tag and holds her phone up to touch the area marked as the tag. The tag can then transfer additional data to the mobile device. The device can take whatever action the application thinks is necessary, from simply displaying text and links to opening links in the transferred data.

The example declares a NearField element with id nearfield. This includes a filter constructed from two NdefFilters. The filters have the type specified by a string such as "urn:nfc:wkt:U", which identifies the type as being an NFC Well Known Type, that is predefined, of "U" representing a URL. The other NdefFilter element is for a Well Known Type of "T" (Text).

         filter: [
             NdefFilter { type: "urn:nfc:wkt:U"; minimum: 1; maximum: 1 },
             NdefFilter { type: "urn:nfc:wkt:T"; minimum: 1 }
         ]

The NearField element has the properties of filter, messageRecords and orderMatch. In this example the filter component contains the two NdefFilter elements, the orderMatch property is not used in this example and the messageRecords property is a list of NdefRecords containing the results of the last read. When the signal messageRecordsChanged() is emitted the slot onMessageRecordsChanged will iterate through the messageRecords selecting particular types. After all records in the messageRecords list have been examined the state of the example is set to "Show" which displays the results.

         onMessageRecordsChanged: {
             posterText.text = "";
             posterImage.source = "";
             posterUrl.text = "";

             var currentLocaleMatch = NdefTextRecord.LocaleMatchedNone;
             var i;
             for (i = 0; i < messageRecords.length; ++i) {
                 if (messageRecords[i].recordType == "urn:nfc:wkt:T") {
                     if (messageRecords[i].localeMatch > currentLocaleMatch) {
                         currentLocaleMatch = messageRecords[i].localeMatch;
                         posterText.text = messageRecords[i].text;
                     }
                 } else if (messageRecords[i].recordType == "urn:nfc:wkt:U") {
                     posterUrl.text = messageRecords[i].uri;
                 } else if (messageRecords[i].recordType.substr(0, 19) == "urn:nfc:mime:image/") {
                     posterImage.source = messageRecords[i].uri;
                 }
             }

             root.state = "show";
         }
X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.