Protobuf Qt Core Types Module | Qt Protobuf | Qt 6.12.0
Description: Provides support for using native Qt Core types in protobuf.
Keywords: module

- Qt 6.12
- Qt Protobuf
- Protobuf Qt Core Types Module
- Qt 6.12.0 Reference Documentation

# Protobuf Qt Core Types Module

Provides support for using native Qt Core types in protobuf. More...

This module was introduced in Qt 6.6.

## Detailed Description

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:

- QByteArray

  Note: Type reflects the bytes protobuf type.

- QChar
- QDate
- QTimeZone
- QDateTime
- QPoint
- QPointF
- QRect
- QRectF
- QSize
- QSizeF
- QString

  Note: Type reflects the string protobuf type.

- QTime
- QUrl
- QUuid
- QVersionNumber

### Qt Core usage

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.

In CMake, you can extract the proto include path from the library using the `QT_PROTO_INCLUDES` target property:

     qt_add_protobuf(MyProtoLib
         PROTO_FILES
             MyQtCoreTypesUsage.proto
         PROTO_INCLUDES
             $<TARGET_PROPERTY:Qt::ProtobufQtCoreTypes,QT_PROTO_INCLUDES>
     )