En esta página

Comandos CMake en Qt6 Protobuf

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

find_package(Qt6 REQUIRED COMPONENTS Protobuf)

target_link_libraries(mytarget PRIVATE Qt6::Protobuf)

Puede utilizar el qt_add_protobuf CMake comando para llamar implícitamente Qt Protobuf generación de código para su proyecto.

Uso de qt_add_protobuf

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

find_package(Qt6 REQUIRED COMPONENTS Protobuf)
qt_standard_project_setup()

qt_add_protobuf(MyMessages
    GENERATE_PACKAGE_SUBFOLDERS
    PROTO_FILES
        path/to/message.proto
        path/to/other_message.proto
    PROTO_INCLUDES
        /path/to/proto/include
)

qt_add_executable(MyApp main.cpp)

target_link_libraries(MyApp PRIVATE MyMessages)

En el ejemplo anterior, generamos una biblioteca llamada MyMessages, que contiene los tipos de mensaje definidos en las rutas pasadas a la opción PROTO_FILES. La opción GENERATE_PACKAGE_SUBFOLDERS para generar una estructura de carpetas para los archivos generados. Y la opción PROTO_INCLUDES le dice a protoc que busque dependencias o importaciones en los directorios especificados. Creamos un objetivo para un ejecutable llamado MyApp, que enlazamos con la librería MyMessages.

Ver también CMake Command Reference.

qt_add_protobuf

Genera código fuente C++ basado en Qt utilizando 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.