Comandos CMake en Qt6 GRPC

Debes invocar los siguientes comandos CMake para usar el módulo Qt6::Grpc en tu proyecto:

find_package(Qt6 REQUIRED COMPONENTS Grpc)

target_link_libraries(mytarget PRIVATE Qt6::Grpc)

Puede utilizar el comando qt_add_grpc CMake para llamar implícitamente a la generación de código Qt GRPC para su proyecto.

Para generar gRPC servicios utilizando Qt GRPC y vincularlos con su programa considere el siguiente ejemplo:

cmake_minimum_required(VERSION 3.16...3.22)
project(MyProject)

find_package(Qt6 REQUIRED COMPONENTS Protobuf Grpc)
qt_standard_project_setup()

qt_add_executable(MyApp main.cpp)

qt_add_protobuf(MyApp
    PROTO_FILES
        path/to/messages.proto
)

qt_add_grpc(MyApp CLIENT
    PROTO_FILES
        path/to/service.proto
)

target_link_libraries(MyApp PRIVATE Qt6::Protobuf Qt6::Grpc)

El ejemplo anterior llama a la función CMake qt_add_grpc() para iniciar la generación de código Qt GRPC para las secciones service dentro del esquema protobuf proporcionado.

Nota: Si el esquema protobuf también contiene definiciones message, la función qt_add_protobuf() CMake también debe ser llamada para iniciar la generación de código Qt Protobuf.

Dado que reutilizamos el objetivo ejecutable, todos los archivos generados se anexarán al objetivo, y los directorios de inclusión se actualizarán en consecuencia.

Ver también CMake Command Reference.

qt_add_grpc

Genera servicios C++ basados en Qt usando un esquema protobuf

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.