QQmlNdefRecord Class

The QQmlNdefRecord class implements the NdefRecord type in QML. More...

Header: #include <QQmlNdefRecord>
qmake: QT += nfc
Instantiated By: NdefRecord

Public Types

enum TypeNameFormat { Empty, NfcRtd, Mime, Uri, ExternalRtd }

Properties

Public Functions

QQmlNdefRecord(QObject * parent = 0)
QQmlNdefRecord(const QNdefRecord & record, QObject * parent = 0)
QNdefRecord record() const
void setRecord(const QNdefRecord & record)
void setType(const QString & newtype)
void setTypeNameFormat(TypeNameFormat newTypeNameFormat)
QString type() const
TypeNameFormat typeNameFormat() const

Signals

void recordChanged()
void typeChanged()
void typeNameFormatChanged()

Macros

Q_DECLARE_NDEFRECORD( className, typeNameFormat, type)

Detailed Description

The QQmlNdefRecord class implements the NdefRecord type in QML.

The QQmlNdefRecord class is the base class for all NdefRecord types in QML. To support a new NDEF record type in QML subclass this class and expose new properties, member functions and signals appropriate for the new record type. The following must be done to create a new NDEF record type in QML:

  • The subclass must have a Q_OBJECT macro in its declaration.
  • The subclass must have an invokable constructor that takes a QNdefRecord and a QObject pointer.
  • The subclass must be declared as an NDEF record by expanding the Q_DECLARE_NDEFRECORD() macro in the implementation file of the subclass.
  • The subclass must be registered with QML.

For example the declaration of such a class may look like the following.

class QQmlNdefFooRecord : public QQmlNdefRecord
{
    Q_OBJECT

    Q_PROPERTY(int foo READ foo WRITE setFoo NOTIFY fooChanged)

public:
    explicit QQmlNdefFooRecord(QObject *parent = 0);
    Q_INVOKABLE QQmlNdefFooRecord(const QNdefRecord &record, QObject *parent = 0);
    ~QQmlNdefFooRecord();

    int foo() const;
    void setFoo(int value);

signals:
    void fooChanged();
};

Within the implementation file the Q_DECLARE_NDEFRECORD() macro is expanded:

Q_DECLARE_NDEFRECORD(QQmlNdefFooRecord, QNdefRecord::ExternalRtd, "com.example:f")

Finially the application or plugin code calls qmlRegisterType():

qmlRegisterType<QQmlNdefFooRecord>(uri, 1, 0, "NdefFooRecord");

See also NdefRecord.

Member Type Documentation

enum QQmlNdefRecord::TypeNameFormat

This enum describes the type name format of an NDEF record. The values of this enum are according to QNdefRecord::TypeNameFormat

ConstantValueDescription
QQmlNdefRecord::EmptyQNdefRecord::EmptyAn empty NDEF record, the record does not contain a payload.
QQmlNdefRecord::NfcRtdQNdefRecord::NfcRtdThe NDEF record type is defined by an NFC RTD Specification.
QQmlNdefRecord::MimeQNdefRecord::MimeThe NDEF record type follows the construct described in RFC 2046.
QQmlNdefRecord::UriQNdefRecord::UriThe NDEF record type follows the construct described in RFC 3986.
QQmlNdefRecord::ExternalRtdQNdefRecord::ExternalRtdThe NDEF record type follows the construct for external type names described the NFC RTD Specification.

Property Documentation

record : QNdefRecord

This property hold the NDEF record that this class represents.

Access functions:

QNdefRecord record() const
void setRecord(const QNdefRecord & record)

Notifier signal:

void recordChanged()

type : QString

This property hold the type of the NDEF record.

Access functions:

QString type() const
void setType(const QString & newtype)

Notifier signal:

void typeChanged()

typeNameFormat : TypeNameFormat

This property hold the TNF of the NDEF record.

Access functions:

TypeNameFormat typeNameFormat() const
void setTypeNameFormat(TypeNameFormat newTypeNameFormat)

Notifier signal:

void typeNameFormatChanged()

Member Function Documentation

QQmlNdefRecord::QQmlNdefRecord(QObject * parent = 0)

Constructs a new empty QQmlNdefRecord with parent.

QQmlNdefRecord::QQmlNdefRecord(const QNdefRecord & record, QObject * parent = 0)

Constructs a new QQmlNdefRecord representing record. The parent of the newly constructed object will be set to parent.

Macro Documentation

Q_DECLARE_NDEFRECORD( className, typeNameFormat, type)

This macro ensures that className is declared as the class implementing the NDEF record identified by typeNameFormat and type.

This macro should be expanded in the implementation file for className.