QtProtobuf Namespace
QtProtobuf 命名空间包含支持Qt Protobuf 所需的类型别名和类。更多内容...
| 头文件: | #include <QtProtobuf> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Protobuf) target_link_libraries(mytarget PRIVATE Qt6::Protobuf) |
| 自: | Qt 6.5 |
类
(since 6.6) class | Any |
类型
| enum class | WireTypes { Unknown, Varint, Fixed64, LengthDelimited, StartGroup, …, Fixed32 } |
| boolList | |
| doubleList | |
| fixed32 | |
| fixed64 | |
| fixed32List | |
| fixed64List | |
| floatList | |
| int32 | |
| int64 | |
| int32List | |
| int64List | |
| sfixed32 | |
| sfixed64 | |
| sfixed32List | |
| sfixed64List | |
| sint32 | |
| sint64 | |
| sint32List | |
| sint64List | |
| uint32 | |
| uint64 | |
| uint32List | |
| uint64List |
函数
| void | qRegisterProtobufEnumType() |
| void | qRegisterProtobufMapType() |
| void | qRegisterProtobufType() |
| void | qRegisterProtobufTypes() |
| void | registerProtobufQtCoreTypes() |
| void | registerProtobufQtGuiTypes() |
类型文档
enum class QtProtobuf::WireTypes
WireTypes 枚举反映了 Protobuf 的默认线类型。
下表列出了该枚举中的值及其对应的类型:
| 常量 | 值 | 描述 |
|---|---|---|
QtProtobuf::WireTypes::Unknown | -1 | 无效的线类型 |
QtProtobuf::WireTypes::Varint | 0 | int32、int64、uint32、uint64、sint32、sint64、bool、enum |
QtProtobuf::WireTypes::Fixed64 | 1 | fixed64、sfixed64、double |
QtProtobuf::WireTypes::LengthDelimited | 2 | 字符串、字节、嵌入式消息、紧凑重复字段 |
QtProtobuf::WireTypes::StartGroup | 3 | 组。在 proto 语法 3 中已弃用。Qt Protobuf 不支持。 |
QtProtobuf::WireTypes::EndGroup | 4 | 组。在 proto 语法 3 中已弃用。Qt Protobuf 不支持。 |
QtProtobuf::WireTypes::Fixed32 | 5 | fixed32、sfixed32、float |
另请参阅 “编码”。
[alias] QtProtobuf::boolList
布尔值列表的别名。
[alias] QtProtobuf::doubleList
双精度数组的别名。
[alias] QtProtobuf::fixed32
fixed32 是一个无符号 32 位整数,在 Protobuf 中以固定大小的 32 位字段表示,它是WireTypes::Fixed32 的别名。
[alias] QtProtobuf::fixed64
fixed64 是一个无符号 64 位整数,在 Protobuf 中以固定长度的 64 位字段表示,它是WireTypes::Fixed64 的别名。
[alias] QtProtobuf::fixed32List
QtProtobuf::fixed32 列表的别名。
[alias] QtProtobuf::fixed64List
QtProtobuf::fixed64 列表的别名。
[alias] QtProtobuf::floatList
浮点数列表的别名。
[alias] QtProtobuf::int32
int32 是一种常规的有符号 32 位整数,在 Protobuf 中以可变长度整数的形式表示,它是WireTypes::Varint 的别名。
[alias] QtProtobuf::int64
int64 是一种普通的有符号 64 位整数,在 Protobuf 中以可变长度整数的形式表示,它是WireTypes::Varint 的别名。
[alias] QtProtobuf::int32List
QtProtobuf::int32 列表的别名。
[alias] QtProtobuf::int64List
QtProtobuf::int64 列表的别名。
[alias] QtProtobuf::sfixed32
sfixed32 是一个有符号的 32 位整数,在 Protobuf 中以固定大小的 32 位字段表示,它是WireTypes::Fixed32 的别名。
[alias] QtProtobuf::sfixed64
sfixed64 是一个有符号的 64 位整数,在 protobuf 中以固定长度的 64 位字段表示,它是WireTypes::Fixed64 的别名。
[alias] QtProtobuf::sfixed32List
QtProtobuf::sfixed32 的列表别名。
[alias] QtProtobuf::sfixed64List
QtProtobuf::sfixed64 列表的别名。
[alias] QtProtobuf::sint32
sint32 是一种带有强制符号标记的 32 位整数,在 Protobuf 中以可变长度整数的形式表示,是 `WireTypes::Varint` 的别名。sint32 采用 ZigZag 转换进行序列化,以减小负数的大小。
另请参阅 signed-integers。
[alias] QtProtobuf::sint64
sint64 是一种带有强制符号标记的 64 位整数,在 Protobuf 中以可变长度整数的形式表示,它是WireTypes::Varint 的别名。sint64 采用 ZigZag 转换进行序列化,以减小负数的大小。
另请参阅 signed-integers。
[alias] QtProtobuf::sint32List
QtProtobuf::sint32 列表的别名。
[alias] QtProtobuf::sint64List
QtProtobuf::sint64 列表的别名。
[alias] QtProtobuf::uint32
uint32 是一个无符号 32 位整数,在 Protobuf 中以可变长度整数的形式表示,它是WireTypes::Varint 的别名。
[alias] QtProtobuf::uint64
uint64 是一个无符号的 64 位整数,在 Protobuf 中以可变长度整数的形式表示,是WireTypes::Varint 的别名。
[alias] QtProtobuf::uint32List
QtProtobuf::uint32 列表的别名。
[alias] QtProtobuf::uint64List
QtProtobuf::uint64 列表的别名。
函数文档
template <typename T, std::enable_if_t<std::is_enum<T>::value, bool> = true> void qRegisterProtobufEnumType()
将枚举类型 `T ` 的序列化器注册到 `QtProtobuf ` 全局序列化器注册表中。
该函数通常由生成的代码调用。
template <typename K, typename V> requires QtProtobuf::if_protobuf_map<K, V> void qRegisterProtobufMapType()
注册 Protobuf 映射类型K 和V 。V 必须是QProtobufMessage 。该函数通常由生成的代码调用。
template <typename T> requires QtProtobuf::if_protobuf_message<T> void qRegisterProtobufType()
注册一个 Protobuf 类型T。该函数通常由生成的代码调用。
void qRegisterProtobufTypes()
调用此函数将把所有当前已知的 Protobuf 类型注册到序列化器注册表中。
注意:仅 从 Qt 6.6.3 版本开始,您无需手动调用此函数,因为它会自动被调用。对于更早的版本,建议在尝试序列化/反序列化之前调用它。
void QtProtobuf::registerProtobufQtCoreTypes()
为 Qt::ProtobufQtCoreTypes 库注册序列化器。
void QtProtobuf::registerProtobufQtGuiTypes()
为 Qt::ProtobufQtGuiTypes 库注册序列化器。
© 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.