Comandos de CMake en Qt6 Protobuf
Debes ejecutar los siguientes comandos de CMake para utilizar el módulo Qt6::Protobuf en tu proyecto:
find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)Puedes utilizar el comando CMake ` qt_add_protobuf ` para invocar de forma implícita la generación de código d Qt Protobuf para tu 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 mensajes definidos en las rutas pasadas a la opción PROTO_FILES. La opción GENERATE_PACKAGE_SUBFOLDERS sirve para generar una estructura de carpetas para los archivos generados. Y la opción PROTO_INCLUDES indica a protoc que busque dependencias o importaciones en los directorios especificados. Creamos un objetivo para un ejecutable llamado MyApp, que enlazamos con la biblioteca MyMessages.
Véase también la Referencia de comandos de CMake.
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.