Provides support for using native Qt Core types in protobuf. 更多...
此模块在 技术预览 状态。
This module was introduced in Qt 6.6.
Qt::ProtobufQtCoreTypes is a library with pre-defined protobuf messages designed to encapsulate a selection of Qt Core types.
List of supported Qt Core types:
注意: Type reflects the bytes protobuf type.
注意: Type reflects the string protobuf type.
To enable Qt Core types support, add ProtobufQtCoreTypes as a dependency to your CMake project:
... find_package(Qt REQUIRED COMPONENTS Protobuf ProtobufQtCoreTypes) ... # After target creation target_link_libraries(${TARGET} PRIVATE Qt::ProtobufQtCoreTypes)
Before any serialization or deserialization of messages that use Qt Core types as fields, call the registration method:
// e.g. in main.cpp QtProtobuf::qRegisterProtobufQtCoreTypes(); ...
All supported messages are described in a special .proto file, QtCore .proto , that describes Qt types from the Qt Core module.
You can also use the file to generate code for other languages or frameworks.
Import the required Qt Core types module in your interface .proto file. For example:
syntax = "proto3"; package project.module.component; import "QtCore/QtCore.proto"; message QUrlMessage { QtCore.QUrl url = 1; }
The Qt Protobuf generator detects Qt Core types, supplied by the ProtobufQtCoreTypes package, and uses them directly. This gives you the flexibility to use these types without additional conversion.