本页内容

QProtobufSerializer Class

QProtobufSerializer 类是一个接口,用于实现序列化和反序列化的基本功能。更多内容...

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

公共函数

QProtobufSerializer()
virtual ~QProtobufSerializer() override
(since 6.7) void shouldPreserveUnknownFields(bool preserveUnknownFields)

重新实现的公共函数

virtual QAbstractProtobufSerializer::Error lastError() const override
virtual QString lastErrorString() const override

详细说明

QProtobufSerializer 类为实现 Protobuf 消息且继承自QProtobufMessage 的类注册序列化器/反序列化器。这些类是基于.proto 文件,通过 CMake 函数qt_add_protobuf或直接运行qtprotobufgen自动生成的。

成员函数文档

QProtobufSerializer::QProtobufSerializer()

创建一个新的序列化器实例。

[override virtual noexcept] QProtobufSerializer::~QProtobufSerializer()

销毁序列化器实例。

[override virtual] QAbstractProtobufSerializer::Error QProtobufSerializer::lastError() const

重写了:QAbstractProtobufSerializer::lastError() const。

返回该序列化器实例的最后一次反序列化错误。

另请参阅 lastErrorString()。

[override virtual] QString QProtobufSerializer::lastErrorString() const

重写:QAbstractProtobufSerializer::lastErrorString() const。

返回该序列化器实例的最后一次反序列化错误字符串。

另请参阅 lastError()。

[since 6.7] void QProtobufSerializer::shouldPreserveUnknownFields(bool preserveUnknownFields)

根据preserveUnknownFields ,控制从数据线接收到的未知字段应存储在生成的消息中,还是应被省略。

该函数于 Qt 6.7 中引入。

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