이 페이지에서

Qt Protobuf Well-Known Types C++ Classes

Qt Protobuf 잘 알려진 유형 모듈은 잘 알려진 유형 패키지에서 제공되는 일부 유형에 대한 지원을 제공합니다. 더 보기...

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

클래스

QtProtobuf::Any

프로토뷰 Any 형 작업을 단순화하기 위한 헬퍼 클래스

자세한 설명

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

프로토비프웰노운타입 라이브러리 사용하기

프로젝트에서 잘 알려진 유형을 사용하려면 인터페이스에 해당 구글 .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)

프로토부프웰노운타입에 대한 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_TYPEQML_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.