Protobuf Qt GUI Types Module
为在 Protobuf 中使用本地 Qt GUI 类型提供支持。更多
该模块在 Qt 6.6 中引入。
详细说明
Qt::ProtobufQtGUITypes 是一个具有预定义 protobuf 消息的库,旨在封装一系列 Qt Gui 类型。
支持的 Qt GUI 类型列表:
Qt GUI 使用
要启用Qt GUI 类型支持,请将 ProtobufQtGuiTypes 作为依赖项添加到 CMake 项目中:
... find_package(Qt REQUIRED COMPONENTS Protobuf ProtobufQtGuiTypes) ... # After target creation target_link_libraries(${TARGET} PRIVATE Qt::ProtobufQtGuiTypes)
在对使用Qt GUI 类型作为字段的消息进行序列化或反序列化之前,请调用注册方法:
// e.g. in main.cpp QtProtobuf::qRegisterProtobufQtGuiTypes(); ...
所有受支持的消息都在一个特殊的 .proto 文件QtGui.proto 中描述,该文件描述了来自Qt GUI 模块的 Qt 类型。
您也可以使用该文件为其他语言或框架生成代码。
在界面 .proto 文件中导入所需的Qt GUI types 模块 例如:
syntax = "proto3"; package project.module.component; import "QtGui/QtGui.proto"; message QMatrix4x4Message { QtGui.QMatrix4x4 matrix = 1; }
Qt Protobuf 生成器会检测到由 ProtobufQtGuiTypes 软件包提供的Qt GUI 类型,并直接使用它们。这样,您就可以灵活地使用这些类型,而无需进行额外的转换。
在 CMake 中,你可以使用QT_PROTO_INCLUDES
target 属性从库中提取 proto 包含路径:
qt_add_protobuf(MyProtoLib PROTO_FILES MyQtGuiTypesUsage.proto PROTO_INCLUDES $<TARGET_PROPERTY:Qt::ProtobufQtGuiTypes,QT_PROTO_INCLUDES> )
QImage 序列化
ProtobufQtGuiTypes 库提供了使用QImage 类的可能性。通常,库会将所有QImage 对象转换为PNG
格式。但如果QImage 是使用https://doc.qt.io/qt-6/qimage.html#Format-enuma {浮点格式}创建的,那么转换为PNG
将导致数据丢失。为防止数据丢失,如果系统支持TIFF
格式,程序库会自动将图像文件转换为该格式,否则会转换为PNG
格式。
注意: 如果不想使用TIFF
,则需要将图像明确转换为非浮点格式。
© 2025 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.