Qt Protobuf

Qt Protobuf 生成器插件 生成基于 Qt 的类从 .proto 文件。可以使用这些类,来序列化和反序列化其关联的 Protobuf 消息。

概述

什么是协议缓冲?

Protocol buffers are a language-neutral, platform-neutral, and extensible mechanism for serializing structured data, which is compact and easy to use:

  • A user defines the structure of data in .proto 文件。
  • Proto compiler is invoked at build time on .proto files to generate code in various programming languages.

The provided format is suitable for network traffic or long-term data storage.

协议缓冲解决了哪些问题?

Protocol buffers provide a serialization format for packets of typed and structured data that are up to a few megabytes in size. Moreover, it can be extended with new information without invalidating existing data or requiring code to be updated. For more information, see Protocol Buffers Overview .

What are the benefits of using Qt Protobuf?

You can use a Protocol buffers mechanism in any Qt-based project:

  • No need to call a protocol buffer compiler explicitly.
  • No need to integrate generated code into project tree manually.
  • Convenient serialization and deserialization API.
  • Integrated properties mechanism for generated protobuf messages.
  • Integrated gRPC-client support (see QtGrpc module ).

Incoming features

  • Enabling using Qt Core and Qt GUI types as a part of *.proto schema.
  • Enabling gRPC-server support.
  • Enabling QML-types support for generated protobuf messages.

使用 Qt Protobuf

Google protocol buffers provide a generator called protoc that supports extensions. qtprotobufgen 工具 is an extension for protoc and requires that you install protoc on your host system. For more information about the installation, see Protoc Installation .

Example of installation for Linux, using apt :

apt install -y protobuf-compiler
protoc --version  # Ensure compiler version is 3+
					

For more information about component API usage, see CMake API .

CMake API

类文档编制

C++ 类

范例