QtProtobuf  0.6
Protobuf plugin to generate Qt classes
QtProtobufQtTypes

Provides support of native Qt types.

Provides support of native Qt types.

Like Google Protocol Buffers provide bench of standard types, QtProtobuf give you possibility to use Qt types directly in your projects. QtProtobufQtTypes library makes this possible.

List of supported types:

QtCore
  • QUrl
  • QChar
  • QUuid
  • QTime
  • QDate
  • QDateTime
  • QSize
  • QSizeF
  • QPoint
  • QPointF
  • QRect
  • QRectF
  • QPolygon
  • QPolygonF
QtGui
  • QColor
  • QMatrix4x4
  • QVector2D
  • QVector3D
  • QVector4D
  • QTransform
  • QQuaternion
  • QImage
Note
To request support of any other Qt meta type please submit feature issue in project bugtracker.

Usage

To enable Qt types support add ProtobufQtTypes as dependency to CMake project:

...
find_package(QtProtobuf CONFIG COMPONENTS ProtobufGenerator Protobuf ProtobufQtTypes REQUIRED)
... #After target creation
target_link_libraries(${TARGET} PRIVATE ${QT_PROTOBUF_NAMESPACE}::ProtobufQtTypes)

Starting from this point you are almost complete preparation. Unlike automatical registration of generated code, QtProtobufQtTypes requires additional intialization step. Before any serialization/deserialization of messages that use Qt types as fields, call registration method:

... //E.g. somewhere in main.cpp
QtProtobuf::qRegisterProtobufQtTypes();
...

All supported message are described in special .proto files:

These files also useful if you would like to generate code for other languages or frameworks. They located in project include directories, but no need to specify anything manualy, qtprotobuf_generate macro takes care about all side work for you.

Import required Qt types module in your interface .proto file, e.g.:

syntax = "proto3";
package project.module.component;
import "QtProtobuf/QtCore.proto";
message QUrlMessage {
QtProtobuf.QUrl url = 1;
}

QtProtobuf generator detects fields of type is located in QtProtobuf package and use Qt type directly instead of complex message generation. This give you flexibility to use Qt types without additional convertion steps.

In generated code you will see following property ready to use:

class QUrlMessage : public QObject
{
...
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged SCRIPTABLE true)
...
}