IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

CMake Commands in Qt6 GRPC

Qt GRPC Reference Documentation.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

CMake Commands in Qt6 GRPC

You should call the following CMake commands to use the Qt6::Grpc module in your project:

 
Sélectionnez
find_package(Qt6 REQUIRED COMPONENTS Grpc)

target_link_libraries(mytarget PRIVATE Qt6::Grpc)

To generate gRPC services using Qt GRPC and link them with your program consider the following example:

 
Sélectionnez
cmake_minimum_required(VERSION 3.16...3.22)
project(MyProject)

find_package(Qt6 REQUIRED COMPONENTS Protobuf Grpc)
qt_standard_project_setup()

qt_add_protobuf(MyProtoMessageLib
    PROTO_FILES
        path/to/helloworld.proto
    PROTO_INCLUDES
        path/to/proto/include
)

qt_add_grpc(MyGrpcClient CLIENT
    PROTO_FILES
        path/to/helloworld.proto
    PROTO_INCLUDES
        path/to/proto/include
)

qt_add_executable(MyApp main.cpp)

target_link_libraries(MyApp PRIVATE MyGrpcClient MyProtoMessageLib Qt6::Protobuf)

The example above calls the qt_add_grpc() CMake function to generate a library called MyGrpcClient.

if the .proto file API contains messages, then the qt_add_protobuf() CMake function should be called to generate protobuf message classes for the project.

Finally, the example creates a target for an executable called MyApp which links to the MyGrpcClient and MyProtoMessageLib libraries.

See Also

Contents

  • qt_add_grpc: Generates Qt-based C++ services using a protobuf schema

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+