- Qbs Manual
- Qbs 1.21.0

# protobuf.cpp QML Type

Provides support for protocol buffers for the C++ language. More...

Import Statement: | import QbsModules .
Since: | Qbs 1.13

- List of all members, including inherited members

## Properties

- compilerName : string
- compilerPath : string
- grpcIncludePath : string
- grpcLibraryPath : string
- importPaths : pathList
- includePath : string
- libraryPath : string
- outputDir : string
- useGrpc : bool

## Detailed Description

The `protobuf.cpp` module provides support for generating C++ headers and sources from proto definition files using the protoc tool.

A simple qbs file that uses protobuf can be written as follows:

     CppApplication {
         Depends { name: "protobuf.cpp" }
         files: ["foo.proto", "main.cpp"]
     }

A generated header now can be included in the C++ sources:

     #include <foo.pb.h>

     int main(int argc, char* argv[]) {
         Foo bar;
         bar.set_answer(42);
         google::protobuf::ShutdownProtobufLibrary();
         return 0;
     }

### Relevant File Tags

Tag | Auto-tagged File Names | Since | Description
--- | --- | --- | ---
`"protobuf.input"` | `*.proto` | 1.13.0 | Source files with this tag are considered inputs to the `protoc` compiler.
`"protobuf.grpc"` |  | 1.14.0 | Source files with this tag are considered as gRPC files.
`"protobuf.hpp"` |  | 1.18.0 | This tag is attached to the header files generated by `protoc` compiler.

## Property Documentation

compilerName : string

The name of the protoc binary.

Default: `"protoc"`

This property was introduced in Qbs 1.17.

compilerPath : string

The path to the protoc binary.

Use this property to override the auto-detected location.

Default: `auto-detected`

This property was introduced in Qbs 1.17.

grpcIncludePath : string

The path where grpc++ headers are located. Set this property to override the default location.

Default: `auto-detected`

grpcLibraryPath : string

The path where the grpc++ library is located. Set this property to override the default location.

Default: `auto-detected`

importPaths : pathList

The list of imports that are passed to the `protoc` tool via the `--proto_path` option. These imports should contain the proto files. They are used to determine the relative structure of the generated files.

Note: The paths are passed to `protoc` in the same order as specified in this property and `protoc` output may differ depending on that order.

Default: `[]`

includePath : string

The path where protobuf C++ headers are located. Set this property to override the default location.

Default: `auto-detected`

libraryPath : string

The path where the protobuf C++ library is located. Set this property to override the default location.

Default: `auto-detected`

[read-only] outputDir : string

The directory where the `protoc` compiler generated files are placed.

The value of this property is automatically set by Qbs and cannot be changed by the user.

useGrpc : bool

Whether to use gRPC framework.

Use this property to enable support for the modern open source high performance RPC framework by Google, gRPC (https://www.grpc.io).

A simple qbs file that uses grpc can be written as follows:

     CppApplication {
         Depends { name: "protobuf.cpp" }
         protobuf.cpp.useGrpc: true
         files: ["main.cpp"]
         Group {
             files: "grpc.proto"
             fileTags: "protobuf.grpc"
         }
     }

Note: that `protobuf.grpc` tag should be assigned manually because gRPC uses same `*.proto` files and Qbs can't detect whether to generate gRPC or `protobuf`.

The following `grpc.proto` file...

     syntax = "proto3";

     package Qbs;

     message Request {
         string name = 1;
     }

     message Response {
         string name = 1;
     }

     service Grpc {
         rpc doWork(Request) returns (Response) {}
     }

...can be used in the C++ sources as follows:

     #include <grpc.grpc.pb.h>

     class Service final : public Qbs::Grpc::Service
     {
         grpc::Status doWork(
                 grpc::ServerContext* context,
                 const Qbs::Request* request,
                 Qbs::Response* reply) override
         {
             (void)context;
             reply->set_name(request->name());
             return grpc::Status::OK;
         }
     };

Default: `false`