이 페이지에서

Qt Protobuf Well-Known Types C++ Classes

Qt Protobuf 의 ‘Well-Known Types’ 모듈은 ‘Well-Known Types’ 패키지에서 사용할 수 있는 일부 유형을 지원합니다. 더 보기...

이 모듈은 Qt 6.6에서 도입되었습니다.

클래스

QtProtobuf::Any

protobuf Any 유형을 다루는 작업을 간소화하는 헬퍼 클래스

상세 설명

QtProtobufWellKnownTypes에는 다음과 같은 Protobuf 잘 알려진 유형이 포함되어 있습니다: 지원되는 유형:

ProtobufWellKnownTypes 라이브러리 사용

프로젝트에서 잘 알려진 타입을 사용하려면 인터페이스에 해당 Google .proto 파일을 포함시켜야 합니다:

syntax = "proto3";
package somepackage;
import "google/protobuf/any.proto";
message Message {
    google.protobuf.Any payload = 1;
}

나열된 타입을 사용하려면 CMakeLists.txt 파일에 다음 줄을 추가하여 ProtobufWellKnownTypes 라이브러리를 링크해야 합니다:

target_link_libraries(YourTargetName PRIVATE Qt::ProtobufWellKnownTypes)

ProtobufWellKnownTypes에 대한 QML 지원 추가

ProtobufWellKnownTypes 라이브러리는 QML 지원을 제공하지 않습니다. 향후 릴리스에서 지원이 구현될 예정이지만, 당분간은 다음 지침을 따라 Qt Protobuf 의 잘 알려진 타입을 QML 호환 타입으로 확장할 수 있습니다. 예를 들어, Empty는 RPC 메서드의 입력 또는 출력으로 자주 사용됩니다. 아래를 참조하십시오:

syntax = "proto3";
package qtgrpc.examples;
import "google/protobuf/empty.proto";
service ExampleService {
    rpc emptyMethod(google.protobuf.Empty) returns (google.protobuf.Empty) {}
}

QML에서 ` emptyMethod `를 호출하려면, 프로젝트의 헤더 파일 .h 에 다음 코드를 추가하여 ` google.protobuf.Empty ` 타입을 선언하십시오:

#include "google/protobuf/empty.qpb.h"

struct GoogleProtobufAPI
{
    Q_GADGET
    QML_FOREIGN(google::protobuf::Empty)
    QML_STRUCTURED_VALUE
    QML_VALUE_TYPE(protobufEmpty)
};

그러면 QML에서 ` protobufEmpty ` 값 유형을 사용할 수 있습니다. 아래 예제를 참조하십시오:

import qtgrpc.examples
import QtQuick
import QtGrpc

Item {
    id: root
    property protobufEmpty value: null

    ServiceClient {
        id: grpcClient
        channel: grpcChannel.channel
    }

    Item {
        Component.onCompleted: {
            grpcClient.emptyMethod(value, messageCallback, errorCallback, grpcCallOptions);
        }
    }
}

QML_STRUCTURED_VALUE 매크로를 사용하면 다음과 같은 구문도 사용할 수 있습니다:

Component.onCompleted: {
    grpcClient.emptyMethod({}, messageCallback, errorCallback, grpcCallOptions);
}

QML_VALUE_TYPE 및 QML_STRUCTURED_VALUE도 참조하십시오 .

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