Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QNdefRecord Class Reference

The QNdefRecord class provides an NFC NDEF record. More...

#include <qndefrecord.h>

+ Inheritance diagram for QNdefRecord:
+ Collaboration diagram for QNdefRecord:

Public Types

enum  TypeNameFormat {
  Empty = 0x00 , NfcRtd = 0x01 , Mime = 0x02 , Uri = 0x03 ,
  ExternalRtd = 0x04 , Unknown = 0x05
}
 This enum describes the type name format of an NDEF record. More...
 

Public Member Functions

 QNdefRecord ()
 Constructs a new empty NDEF record.
 
 ~QNdefRecord ()
 Destroys the NDEF record.
 
 QNdefRecord (const QNdefRecord &other)
 Constructs a new NDEF record that is a copy of other.
 
QNdefRecordoperator= (const QNdefRecord &other)
 Assigns this NDEF record to other.
 
void setTypeNameFormat (TypeNameFormat typeNameFormat)
 Sets the type name format of the NDEF record to typeNameFormat.
 
TypeNameFormat typeNameFormat () const
 Returns the type name format of the NDEF record.
 
void setType (const QByteArray &type)
 Sets the type of the NDEF record to type.
 
QByteArray type () const
 Returns the type of the NDEF record.
 
void setId (const QByteArray &id)
 Sets the id of the NDEF record to id.
 
QByteArray id () const
 Returns the id of the NDEF record.
 
void setPayload (const QByteArray &payload)
 Sets the payload of the NDEF record to payload.
 
QByteArray payload () const
 Returns the payload of the NDEF record.
 
bool isEmpty () const
 Returns true if the NDEF record contains an empty payload; otherwise returns false.
 
template<typename T >
bool isRecordType () const
 Returns true if the NDEF record is of the specified record type; otherwise returns false.
 
bool operator== (const QNdefRecord &other) const
 Returns true if other and this NDEF record are the same.
 
bool operator!= (const QNdefRecord &other) const
 Returns true if this NDEF record does not equal other; otherwise return false.
 
void clear ()
 

Protected Member Functions

 QNdefRecord (const QNdefRecord &other, TypeNameFormat typeNameFormat, const QByteArray &type)
 
 QNdefRecord (const QNdefRecord &other, TypeNameFormat typeNameFormat)
 
 QNdefRecord (TypeNameFormat typeNameFormat, const QByteArray &type)
 

Related Symbols

(Note that these are not member symbols.)

size_t qHash (const QNdefRecord &key)
 \macro Q_DECLARE_NDEF_RECORD(className, typeNameFormat, type, initialPayload)
 

Detailed Description

The QNdefRecord class provides an NFC NDEF record.

\inmodule QtNfc

Since
5.2

QNdefRecord and derived classes are used to parse the contents of \l {QNdefMessage}{NDEF messages} and create new NDEF messages.

Use typeNameFormat() and setTypeNameFormat() 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.

Definition at line 15 of file qndefrecord.h.

Member Enumeration Documentation

◆ TypeNameFormat

This enum describes the type name format of an NDEF record.

\value Empty An empty NDEF record, the record does not contain a payload \value NfcRtd The NDEF record type is defined by an NFC RTD Specification \value Mime The NDEF record type follows the construct described in RFC 2046 \value Uri The NDEF record type follows the construct described in RFC 3986 \value ExternalRtd The NDEF record type follows the construct for external type names described the NFC RTD Specification \value Unknown The type of the record is unknown and should be treated similar to content with MIME type 'application/octet-stream' without further context

Enumerator
Empty 
NfcRtd 
Mime 
Uri 
ExternalRtd 
Unknown 

Definition at line 18 of file qndefrecord.h.

Constructor & Destructor Documentation

◆ QNdefRecord() [1/5]

QNdefRecord::QNdefRecord ( )

Constructs a new empty NDEF record.

Definition at line 125 of file qndefrecord.cpp.

◆ ~QNdefRecord()

QNdefRecord::~QNdefRecord ( )

Destroys the NDEF record.

Definition at line 189 of file qndefrecord.cpp.

◆ QNdefRecord() [2/5]

QNdefRecord::QNdefRecord ( const QNdefRecord & other)

Constructs a new NDEF record that is a copy of other.

Definition at line 132 of file qndefrecord.cpp.

References other().

+ Here is the call graph for this function:

◆ QNdefRecord() [3/5]

QNdefRecord::QNdefRecord ( const QNdefRecord & other,
TypeNameFormat typeNameFormat,
const QByteArray & type )
protected

Constructs an NDEF record that is a copy of other if other is of the expected type name format identified by typeNameFormat and type as identified by type; otherwise an empty NDEF record of the expected type name format and type is created.

Definition at line 144 of file qndefrecord.cpp.

References other(), type(), QNdefRecordPrivate::type, typeNameFormat(), and QNdefRecordPrivate::typeNameFormat.

+ Here is the call graph for this function:

◆ QNdefRecord() [4/5]

QNdefRecord::QNdefRecord ( const QNdefRecord & other,
TypeNameFormat typeNameFormat )
protected

Constructs an NDEF record that is a copy of other if other is of the expected type name format identified by typeNameFormat; otherwise an empty NDEF record of the expected type name format and type is created.

Definition at line 163 of file qndefrecord.cpp.

References other(), typeNameFormat(), and QNdefRecordPrivate::typeNameFormat.

+ Here is the call graph for this function:

◆ QNdefRecord() [5/5]

QNdefRecord::QNdefRecord ( TypeNameFormat typeNameFormat,
const QByteArray & type )
protected

Constructs an NDEF record with a type name format identified by typeNameFormat and type as identified by type.

Definition at line 179 of file qndefrecord.cpp.

References type(), QNdefRecordPrivate::type, typeNameFormat(), and QNdefRecordPrivate::typeNameFormat.

+ Here is the call graph for this function:

Member Function Documentation

◆ clear()

void QNdefRecord::clear ( )
Since
6.2

Clear the NDEF record.

An \l isEmpty() call returns true for a cleared record. The record \l type() is set to \l {QNdefRecord::}{Empty}.

Definition at line 344 of file qndefrecord.cpp.

References QByteArray::clear(), QNdefRecordPrivate::id, QNdefRecordPrivate::payload, QNdefRecordPrivate::type, and QNdefRecordPrivate::typeNameFormat.

+ Here is the call graph for this function:

◆ id()

QByteArray QNdefRecord::id ( ) const

Returns the id of the NDEF record.

Definition at line 265 of file qndefrecord.cpp.

References QNdefRecordPrivate::id, and QByteArray().

Referenced by setId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEmpty()

bool QNdefRecord::isEmpty ( ) const

Returns true if the NDEF record contains an empty payload; otherwise returns false.

This is equivalent to calling {payload().isEmpty()}.

Definition at line 301 of file qndefrecord.cpp.

References QByteArray::isEmpty(), and QNdefRecordPrivate::payload.

Referenced by QNdefNfcTextRecord::encoding(), and QNdefNfcTextRecord::setText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRecordType()

template<typename T >
template< typename T > bool QNdefRecord::isRecordType ( ) const
inline

Returns true if the NDEF record is of the specified record type; otherwise returns false.

Definition at line 48 of file qndefrecord.h.

◆ operator!=()

bool QNdefRecord::operator!= ( const QNdefRecord & other) const
inline

Returns true if this NDEF record does not equal other; otherwise return false.

Definition at line 55 of file qndefrecord.h.

References operator==(), and other().

+ Here is the call graph for this function:

◆ operator=()

QNdefRecord & QNdefRecord::operator= ( const QNdefRecord & other)

Assigns this NDEF record to other.

Definition at line 196 of file qndefrecord.cpp.

References other().

+ Here is the call graph for this function:

◆ operator==()

bool QNdefRecord::operator== ( const QNdefRecord & other) const

Returns true if other and this NDEF record are the same.

Otherwise returns false.

Definition at line 313 of file qndefrecord.cpp.

References QNdefRecordPrivate::id, other(), QNdefRecordPrivate::payload, QNdefRecordPrivate::type, and QNdefRecordPrivate::typeNameFormat.

+ Here is the call graph for this function:

◆ payload()

QByteArray QNdefRecord::payload ( ) const

Returns the payload of the NDEF record.

Definition at line 287 of file qndefrecord.cpp.

References QNdefRecordPrivate::payload, and QByteArray().

Referenced by QNdefNfcActRecord::action(), QNdefNfcIconRecord::data(), QNdefNfcTextRecord::encoding(), QNdefNfcTextRecord::setEncoding(), QNdefNfcTextRecord::setLocale(), QNdefNfcSmartPosterRecord::setPayload(), setPayload(), QNdefNfcTextRecord::setText(), QNdefNfcSizeRecord::size(), QNdefNfcTextRecord::text(), and QNdefNfcTypeRecord::typeInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setId()

void QNdefRecord::setId ( const QByteArray & id)

Sets the id of the NDEF record to id.

Definition at line 254 of file qndefrecord.cpp.

References id(), and QNdefRecordPrivate::id.

+ Here is the call graph for this function:

◆ setPayload()

void QNdefRecord::setPayload ( const QByteArray & payload)

Sets the payload of the NDEF record to payload.

Definition at line 276 of file qndefrecord.cpp.

References payload(), and QNdefRecordPrivate::payload.

Referenced by QNdefNfcTextRecord::setEncoding(), QNdefNfcTextRecord::setLocale(), QNdefNfcSmartPosterRecord::setPayload(), QNdefNfcTextRecord::setText(), and QNdefNfcUriRecord::setUri().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setType()

void QNdefRecord::setType ( const QByteArray & type)

Sets the type of the NDEF record to type.

Definition at line 232 of file qndefrecord.cpp.

References type(), and QNdefRecordPrivate::type.

Referenced by QNdefNfcSmartPosterRecord::addIcon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTypeNameFormat()

void QNdefRecord::setTypeNameFormat ( TypeNameFormat typeNameFormat)

Sets the type name format of the NDEF record to typeNameFormat.

Definition at line 207 of file qndefrecord.cpp.

References typeNameFormat(), and QNdefRecordPrivate::typeNameFormat.

+ Here is the call graph for this function:

◆ type()

QByteArray QNdefRecord::type ( ) const

Returns the type of the NDEF record.

Definition at line 243 of file qndefrecord.cpp.

References QByteArray(), and QNdefRecordPrivate::type.

Referenced by QNdefRecord(), QNdefRecord(), QNdefNfcSmartPosterRecord::removeIcon(), QNdefNfcSmartPosterRecord::removeIcon(), and setType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ typeNameFormat()

QNdefRecord::TypeNameFormat QNdefRecord::typeNameFormat ( ) const

Returns the type name format of the NDEF record.

Definition at line 218 of file qndefrecord.cpp.

References Empty, QNdefRecordPrivate::typeNameFormat, and Unknown.

Referenced by QNdefRecord(), QNdefRecord(), QNdefRecord(), and setTypeNameFormat().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ qHash()

size_t qHash ( const QNdefRecord & key)
related

\macro Q_DECLARE_NDEF_RECORD(className, typeNameFormat, type, initialPayload)

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 \l {Creating specialized NDEF record classes} for details.

See also
Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD()

\macro Q_DECLARE_ISRECORDTYPE_FOR_NDEF_RECORD(className, typeNameFormat, type)

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 section on \l {Creating specialized NDEF record classes} for details.

See also
Q_DECLARE_NDEF_RECORD()

Definition at line 117 of file qndefrecord.cpp.

References qHash().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: