Comandi CMake in Qt6 GRPC
Per utilizzare il modulo Qt6::Grpc nel proprio progetto, è necessario eseguire i seguenti comandi CMake:
find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)È possibile utilizzare il comando CMake ` qt_add_grpc ` per attivare implicitamente la generazione del codic Qt GRPC e per il proprio progetto.
Per generare gRPC™ servizi utilizzando Qt GRPC e collegarli al proprio programma, si consideri il seguente esempio:
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)L’esempio sopra riportato richiama la funzione CMake ` qt_add_grpc() ` per avviare la generazione del cod Qt GRPC e per le sezioni ` service ` all’interno dello schema protobuf fornito.
Nota: se lo schema protobuf contiene anche definizioni ` message `, è necessario richiamare anche la funzione CMake ` qt_add_protobuf() ` per avviare la generazione del codice ` Qt Protobuf `.
Poiché si riutilizza il target eseguibile, tutti i file generati verranno aggiunti al target e le directory di inclusione verranno aggiornate di conseguenza.
Vedi anche Riferimento ai comandi CMake.
Genera servizi C++ basati su Qt utilizzando uno schema 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.