本页内容

QNdefMessage Class

QNdefMessage 类提供了一个 NFC NDEF 消息。更多内容...

头文件: #include <QNdefMessage>
CMake: find_package(Qt6 REQUIRED COMPONENTS Nfc)
target_link_libraries(mytarget PRIVATE Qt6::Nfc)
qmake: QT += nfc
自: Qt 5.2
继承自: QList

公共函数

QNdefMessage()
QNdefMessage(const QList<QNdefRecord> &records)
QNdefMessage(const QNdefRecord &record)
QNdefMessage(const QNdefMessage &message)
QByteArray toByteArray() const
(since 6.2) QNdefMessage &operator=(QNdefMessage &&other)
(since 6.2) QNdefMessage &operator=(const QNdefMessage &other)
bool operator==(const QNdefMessage &other) const

静态公共成员

QNdefMessage fromByteArray(const QByteArray &message)

详细描述

QNdefMessage 是由 0 个或更多 QNdefRecords 组成的集合。QNdefMessage 继承自QList<QNdefRecord>,因此可以使用标准的QList 函数来操作消息中的 NDEF 记录。

可以通过调用静态函数fromByteArray(),从符合 NFC 数据交换格式技术规范的字节数组中解析 NDEF 消息。反之,可通过toByteArray() 函数将 QNdefMessage 转换为字节数组。

成员函数文档

[constexpr noexcept default] QNdefMessage::QNdefMessage()

构建一个新的空NDEF消息。

QNdefMessage::QNdefMessage(const QList<QNdefRecord> &records)

构建一个新的 NDEF 消息,其中包含 `records` 中的所有记录。

[explicit] QNdefMessage::QNdefMessage(const QNdefRecord &record)

构建一个包含单条记录record 的新NDEF消息。

[noexcept default] QNdefMessage::QNdefMessage(const QNdefMessage &message)

创建一个新的 NDEF 消息,该消息是 `message` 的副本。

[static] QNdefMessage QNdefMessage::fromByteArray(const QByteArray &message)

返回从message 内容中解析出的NDEF消息。

message 参数被解释为《NFC 数据交换格式》技术规范中定义的原始消息格式。

如果发生解析错误,则返回一个空的 NDEF 消息。

QByteArray QNdefMessage::toByteArray() const

返回 NDEF 消息,格式为字节数组。

该函数的返回值符合《NFC 数据交换格式》技术规范中定义的格式。

[noexcept default, since 6.2] QNdefMessage &QNdefMessage::operator=(QNdefMessage &&other)

将赋值运算符从QList 移至<QNdefRecord>。将other 中的NDEF记录列表移动到此NDEF记录列表中。

操作完成后,other 将变为空。

这是一个重载函数。

该函数于 Qt 6.2 中引入。

[noexcept default, since 6.2] QNdefMessage &QNdefMessage::operator=(const QNdefMessage &other)

从QList<QNdefRecord> 复制赋值运算符。将other 中的 NDEF 记录列表赋值给此 NDEF 记录列表。

操作完成后,other 和*this 将相等。

这是一个重载函数。

该函数在 Qt 6.2 中引入。

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

如果该 NDEF 消息等同于other ,则返回true ;否则返回false 。

一个空消息(即isEmpty() 返回true )等同于一个包含单条QNdefRecord::Empty 类型记录的 NDEF 消息。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.