このページでは

Protobuf Qt Core Types Module

protobuf でネイティブのQt Core 型を使用するためのサポートを提供します。詳細...

このモジュールはQt 6.6で導入されました。

詳細な説明

Qt::ProtobufQtCoreTypesは、Qt Core の特定の型をカプセル化するように設計された、事前定義済みのprotobufメッセージを含むライブラリです。

サポートされているQt Core 型のリスト:

Qt Core 使用方法

Qt Core 型のサポートを有効にするには、CMakeプロジェクトにProtobufQtCoreTypesを依存関係として追加してください:

...
find_package(Qt REQUIRED COMPONENTS Protobuf ProtobufQtCoreTypes)
... # After target creation
target_link_libraries(${TARGET} PRIVATE Qt::ProtobufQtCoreTypes)

Qt Core 型をフィールドとして使用するメッセージのシリアライズまたはデシリアライズを行う前に、登録メソッドを呼び出してください:

// e.g. in main.cpp
QtProtobuf::qRegisterProtobufQtCoreTypes();
...

サポートされているすべてのメッセージは、Qt Core モジュールのQt型を記述した特別な.protoファイル「QtCore.proto」に記載されています。

このファイルを使用して、他の言語やフレームワーク向けのコードを生成することもできます。

インターフェースの .proto ファイルで、必要なQt Core タイプモジュールをインポートしてください。例:

syntax = "proto3";

package project.module.component;

import "QtCore/QtCore.proto";

message QUrlMessage {
    QtCore.QUrl url = 1;
}

Qt Protobuf ジェネレータは、ProtobufQtCoreTypes パッケージによって提供されるQt Core 型を検出し、それらを直接使用します。これにより、追加の変換を行うことなく、これらの型を柔軟に使用することができます。

CMakeでは、QT_PROTO_INCLUDES ターゲットプロパティを使用して、ライブラリからprotoインクルードパスを抽出できます:

qt_add_protobuf(MyProtoLib
    PROTO_FILES
        MyQtCoreTypesUsage.proto
    PROTO_INCLUDES
        $<TARGET_PROPERTY:Qt::ProtobufQtCoreTypes,QT_PROTO_INCLUDES>
)

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