Qt Protobuf
generator plugin
generates Qt-based classes from
.proto
files. You can use the classes to serialize and deserialize their associated protobuf messages.
Protocol buffers are a language-neutral, platform-neutral, and extensible mechanism for serializing structured data, which is compact and easy to use:
.proto
文件。
.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 .
You can use a Protocol buffers mechanism in any Qt-based project:
Google protocol buffers provide a generator called
protoc
that supports extensions.
The qtprotobufgen Tool
is an extension for
protoc
and requires that you install
protoc
on your host system. For more information about the installation, see
Protoc Installation
.
apt install -y protobuf-compiler protoc --version # Ensure compiler version is 3+
The QML types of the module are available through the QML and QML_URI options in the
qt_add_protobuf
macro. The import name is equal to the
.proto
package name or defined by QML_URI option in the
qt_add_protobuf
macro. To use the types, add the following import statement to your .qml file:
import my.proto.package.uri
使用 Qt 模块的 C++ API 要求直接 (或透过其它依赖) 链接到模块库。几个构建工具对此有专用支持,包括 CMake and qmake .
使用
find_package()
命令定位所需模块组件在
Qt6
包:
find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)
更多细节,见 构建采用 CMake 概述。
The Qt Protobuf module is available under commercial licenses from Qt 公司 。此外,它在自由软件许可下也是可用的: GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 ,或 GNU GPL (一般公共许可) 第 3 版 。见 Qt 许可 进一步了解细节。
Furthermore, the
qtprotobufgen
tool in Qt 6.7.2 may contain third party modules under the following permissive licenses:
BSD 3 条款新 (或修订) 许可 |