The QNdefRecord class provides an NFC NDEF record. More...
#include <QNdefRecord>
Inherited by: QNdefNfcTextRecord and QNdefNfcUriRecord.
This class was introduced in Qt Mobility 1.2.
enum | TypeNameFormat { Empty, NfcRtd, Mime, Uri, ExternalRtd, Unknown } |
QNdefRecord () | |
QNdefRecord ( const QNdefRecord & other ) | |
~QNdefRecord () | |
QByteArray | id () const |
bool | isEmpty () const |
bool | isRecordType () const |
QByteArray | payload () const |
void | setId ( const QByteArray & id ) |
void | setPayload ( const QByteArray & payload ) |
void | setType ( const QByteArray & type ) |
void | setTypeNameFormat ( TypeNameFormat typeNameFormat ) |
QByteArray | type () const |
TypeNameFormat | typeNameFormat () const |
bool | operator!= ( const QNdefRecord & other ) const |
QNdefRecord & | operator= ( const QNdefRecord & other ) |
bool | operator== ( const QNdefRecord & other ) const |
Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD ( className, typeNameFormat, type ) | |
Q_DECLARE_NDEF_RECORD ( className, typeNameFormat, type, initialPayload ) |
The QNdefRecord class provides an NFC NDEF record.
QNdefRecord and derived classes are used to parse the contents of NDEF messages and create new NDEF messages.
Use typeNameFormat(), userTypeNameFormat(), setTypeNameFormat() and setUserTypeNameFormat() to get and set the type name format of the NDEF record.
Use type() and setType() to get and set the type of the NDEF record.
Use id() and setId() to get and set the id of the NDEF record.
Use payload() and setPayload() to get and set the NDEF record payload. isEmpty() can be used to test if the payload is empty.
QNdefRecord is an implicitly shared class. This means you can efficiently convert between QNdefRecord and specialized record classes. The isRecordType() template function can be used to test if a conversion is possible. The following example shows how to test if a QNdefRecord is an NFC RTD Text record and extract the text information from it.
if (record.isRecordType<QNdefNfcTextRecord>()) { QNdefNfcTextRecord textRecord(record); qDebug() << textRecord.text(); }
Specialized NDEF record classes can be easily created with the Q_DECLARE_NDEF_RECORD() and Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD() macros. The following example shows the class declaration of the hypothetical example.com:f record type that encapsulates a single int property foo.
class ExampleComF : public QNdefRecord { public: Q_DECLARE_NDEF_RECORD(ExampleComF, QNdefRecord::ExternalRtd, "example.com:f", QByteArray(sizeof(int), char(0))) int foo() const; void setFoo(int v); }; Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD(ExampleComF, QNdefRecord::ExternalRtd, "example.com:f")
The developer only needs to provide implementations for the foo() and setFoo() functions that parse and set the contents of the NDEF record's payload.
This enum describes the type name format of an NDEF record.
Constant | Value | Description |
---|---|---|
QNdefRecord::Empty | 0x00 | An empty NDEF record, the record does not contain a payload |
QNdefRecord::NfcRtd | 0x01 | The NDEF record type is defined by an NFC RTD Specification |
QNdefRecord::Mime | 0x02 | The NDEF record type follows the construct described in RFC 2046 |
QNdefRecord::Uri | 0x03 | The NDEF record type follows the construct described in RFC 3986 |
QNdefRecord::ExternalRtd | 0x04 | The NDEF record type follows the construct for external type names described the NFC RTD Specification |
QNdefRecord::Unknown | 0x05 | The type of the record is unknown and should be treated similar to content with MIME type 'application/octet-stream' without further context |
Constructs a new empty NDEF record.
Constructs a new NDEF record that is a copy of other.
Destroys the NDEF record.
Returns the id of the NDEF record.
See also setId().
Returns true if the NDEF record contains an empty payload; otherwise return false.
This is equivalent to calling payload().isEmpty().
Returns true if the NDEF record is of the specified record type; otherwise returns false.
Returns the payload of the NDEF record.
See also setPayload().
Sets the id of the NDEF record to id.
See also id().
Sets the payload of the NDEF record to payload.
See also payload().
Sets the type of the NDEF record to type.
See also type().
Sets the type name format of the NDEF record to typeNameFormat.
See also typeNameFormat().
Returns the type of the NDEF record.
See also setType().
Returns the type name format of the NDEF record.
See also setTypeNameFormat().
Returns true if this NDEF record does not equal other; otherwise return false.
Assigns this NDEF record to other.
Returns true if other and this NDEF record are the same.
This macro declares a template specialization for the QNdefRecord::isRecordType() function.
This macro should be used in the header file directly after the definition of a specialized NDEF record class.
className is the name of the specialized class, typeNameFormat is the appropriate QNdefRecord::TypeNameFormat for the custom type and type is the type without the NID or NSS prefixes. That is example.com:f not urn:nfc:ext:example.com:f.
See the secton on Creating specialized NDEF record classes for details.
See also Q_DECLARE_NDEF_RECORD().
This macro declares default and copy constructors for specialized NDEF record classes.
className is the name of the specialized class, typeNameFormat is the appropriate QNdefRecord::TypeNameFormat for the custom type and type is the type without the NID or NSS prefixes. That is example.com:f not urn:nfc:ext:example.com:f. initialPayload is the initial payload of an empty record, it must be a QByteArray or a type that can be implicitly converted into a QByteArray.
See the section on Creating specialized NDEF record classes for details.
See also Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD().
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.