Qt6 GRPC における CMake コマンド

プロジェクトで Qt6::Grpc モジュールを使用するには、以下の CMake コマンドを実行する必要があります:

find_package(Qt6 REQUIRED COMPONENTS Grpc)

target_link_libraries(mytarget PRIVATE Qt6::Grpc)

qt_add_grpcCMake コマンドを使用すると、プロジェクトに対してQt GRPC のコード生成を暗黙的に呼び出すことができます。

xml-ph-0000@deepl.internal を使用して gRPC™Qt GRPC を使用してサービスを生成し、それらをプログラムにリンクするには、次の例を参照してください:

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)

上記の例では、qt_add_grpc() CMake関数を呼び出し、指定されたprotobufスキーマ内のservice セクションに対してQt GRPC コードの生成を開始しています。

注: protobuf スキーマにmessage の定義も含まれている場合は 、Qt Protobuf コードの生成を開始するために、qt_add_protobuf() CMake 関数も呼び出す必要があります。

実行可能ターゲットを再利用するため、生成されたすべてのファイルはターゲットに追加され、インクルードディレクトリもそれに応じて更新されます。

「CMake コマンドリファレンス」も参照してください 。

qt_add_grpc

protobuf スキーマを使用して Qt ベースの C++ サービスを生成する

© 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.