Comandos do CMake no Qt6 Protobuf
Você deve chamar os seguintes comandos do CMake para usar o módulo Qt6::Protobuf em seu projeto:
find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)Você pode usar o comando CMake ` qt_add_protobuf ` para chamar implicitamente a geração de código d Qt Protobuf para o seu projeto.
Usando o `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)No exemplo acima, geramos uma biblioteca chamada ` MyMessages`, que contém os tipos de mensagem definidos nos caminhos passados para a opção ` PROTO_FILES `. A opção ` GENERATE_PACKAGE_SUBFOLDERS ` gera uma estrutura de pastas para os arquivos gerados. E a opção ` PROTO_INCLUDES ` instrui o protoc a procurar dependências ou importações nos diretórios especificados. Criamos um alvo para um executável chamado ` MyApp`, que vinculamos à biblioteca ` MyMessages `.
Consulte também a Referência de Comandos do CMake.
Gera código-fonte C++ baseado em Qt usando um 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.