QtProtobuf  0.6
Protobuf plugin to generate Qt classes
Classes
Generator

QtProtobuf code generator for protobuf messages and grpc services. More...

Detailed Description

QtProtobuf code generator for protobuf messages and grpc services.

QtProtobuf code generator is program to be used in conjunction with proto compiler aka protoc.

It might be used in few ways:

usage

[QT_PROTOBUF_OPTIONS="[SINGLE|MULTI]:QML:COMMENTS:FOLDER"] protoc --plugin=protoc-gen-qtprotobuf=<path/to/bin/>qtprotobufgen --qtprotobuf_out=<output_dir> [-I/extra/proto/include/path] <protofile>.proto

Generator supports options that could be provided as environment variable to tune generation. Following options are supported:

SINGLE - enables single-file generation when for each *.proto* file single pair of *.h* *.cpp* files is generated

Note
Enabled by default. Excluded by SINGLE

MULTI - enables multi-file generation when for each message separate pair of *.h* *.cpp*

Note
Has higher priority than SINGLE

QML - enables QML code generation in protobuf classes. If is set QML-related code for lists and QML registration to be generated.

COMMENTS - enables comments copying from .proto files

FOLDER - enables folder-based generation

CMake

For CMake based project QtProtobuf has macroses those should be used to generate code and in link it to your project:

qtprotobuf_generate

qtprotobuf_generate is cmake helper function that automatically generates STATIC library target from your .proto files

Parameters
TARGETname of you target that generated code archive will be linked to
GENERATED_TARGETname that will be used for generated archive library target. It's usefull when you supposed to have multiple generated targets to be linked to single one.
OUT_DIRoutput directory that will contain generated artifacts. Usually subfolder in build directory should be used
GENERATED_HEADERSList of header files expected after generator job finished
EXCLUDE_HEADERSList of header files to be excluded from pre-parsed list of expected header files (e.g. nested messages that are not supported by QtProtobuf generator)
PROTO_FILESList of .proto files that will be used in generation procedure
MULTIEnables multi-files generation mode. If provided in parameter list generator will create pair of header/source files for each message
Note
multi-files generation mode is defined as deprecated by QtProtobuf team, and might have poor support in future
Parameters
QMLEnables QML code generation in protobuf classes. If provided in parameter list QML related code for lists and QML registration to be generated.
COMMENTSEnables comments copying from .proto files. If provided in parameter list message and field related comments will be copied to generated header files.
FOLDEREnables folder based generation. If provided in parameter list generator will place generated artifacts to folder structure according to package of corresponding .proto file
FIELDENUMEnables generation of field numbers as an enum within the message class.
EXTRA_NAMESPACE<namespace> Wraps the generated code with the specified namespace(EXPERIMENTAL).

qtprotobuf_link_target

qtprotobuf_link_target is cmake helper function that links generated protobuf target to your binary

It's useful when you try to link generated target to shared library or/and to executable that doesn't utilize all protobuf generated classes directly from C++ code, but requires them from QML.

Parameters
TARGETname of target to link to
GENERATED_TARGETprotobuf generated target name

qmake

qtprotobuf_generate

qtprotobuf_generate is qmake helper test function that generates QtProtobuf source code based on files provided by PROTO_FILES global context variable

Parameters
generate_qmlgenerate_qml enables/disables QML code generation in protobuf classes. If set to true QML-related code for lists and QML registration to be generated.