QProtobufMessage Class

所有 protobuf 消息的基类。更多

头文件: #include <QProtobufMessage>
CMake: find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)
Qt 6.5
继承:

QtProtobuf::Any

公共函数

(since 6.8) bool deserialize(QAbstractProtobufSerializer *serializer, QByteArrayView data)
QVariant property(QAnyStringView propertyName) const
(since 6.8) const QtProtobufPrivate::QProtobufPropertyOrdering *propertyOrdering() const
(since 6.8) QByteArray serialize(QAbstractProtobufSerializer *serializer) const
bool setProperty(QAnyStringView propertyName, const QVariant &value)
(since 6.6) bool setProperty(QAnyStringView propertyName, QVariant &&value)
(since 6.7) QList<QByteArray> unknownFieldData(qint32 field) const
(since 6.7) QList<qint32> unknownFieldNumbers() const

静态公共成员

QProtobufMessagePointer constructByName(const QString &messageType)

详细说明

使用setProperty() 和property() 访问消息的属性,而不依赖于消息的内容。

成员函数文档

[static] QProtobufMessagePointer QProtobufMessage::constructByName(const QString &messageType)

使用messageType 构建QProtobufMessage 。返回指向构建的QProtobufMessage 的指针。

该函数试图创建一个类型与messageType 匹配的消息。如果messageType 未知,函数将返回nullptr 。如果在注册表中找不到信息,函数将返回nullptr 。函数调用者将获得所构建信息的所有权。

[since 6.8] bool QProtobufMessage::deserialize(QAbstractProtobufSerializer *serializer, QByteArrayView data)

使用serializerQByteArray data 反序列化此 protobuf 消息。如果反序列化成功,则返回true ,否则返回false

此函数在 Qt 6.8 中引入。

另请参阅 serialize()。

QVariant QProtobufMessage::property(QAnyStringView propertyName) const

获取propertyName 属性的值。

如果不知道propertyName ,则返回的QVariant 无效。

另请参阅 setProperty() 。

[since 6.8] const QtProtobufPrivate::QProtobufPropertyOrdering *QProtobufMessage::propertyOrdering() const

返回派生 protobuf 消息的属性排序指针。

此函数在 Qt 6.8 中引入。

[since 6.8] QByteArray QProtobufMessage::serialize(QAbstractProtobufSerializer *serializer) const

使用serializer 将此 protobuf 消息序列化为QByteArray

此函数在 Qt 6.8 中引入。

另请参阅 deserialize() 。

bool QProtobufMessage::setProperty(QAnyStringView propertyName, const QVariant &value)

propertyName 属性设置为value 中存储的值。

如果propertyName 不是已知字段,则忽略该值,函数返回false

如果无法将value 存储在属性上,则返回false 。否则返回true

另请参阅 property() 。

[since 6.6] bool QProtobufMessage::setProperty(QAnyStringView propertyName, QVariant &&value)

这是一个重载函数。

该函数在 Qt 6.6 中引入。

[since 6.7] QList<QByteArray> QProtobufMessage::unknownFieldData(qint32 field) const

返回未知的field 值,并按照从有线接收到的值进行排序。

此函数在 Qt 6.7 中引入。

[since 6.7] QList<qint32> QProtobufMessage::unknownFieldNumbers() const

返回QtProtobuf 在反序列化过程中不知道的字段编号。

此函数在 Qt 6.7 中引入。

相关非成员

[alias] QProtobufMessagePointer

std::unique_ptr<QProtobufMessage,QProtobufMessageDeleter> 的同义词。用它来管理动态分配的 QProtobufMessages(如调用QProtobufMessage::constructByName 创建的 QProtobufMessages)的生命周期。

© 2025 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.