이 페이지에서

QProtobufMessage Class

모든 Protobuf 메시지의 기본 클래스입니다. 더 보기...

헤더: #include <QProtobufMessage>
CMake: find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)
다음과 같이: Qt 6.5
상속받는 버전:

QtProtobuf::Any

공개 함수

(since 6.8) bool deserialize(QAbstractProtobufSerializer *serializer, QByteArrayView data)
QVariant property(QAnyStringView propertyName) const
(since 6.8) const QtProtobufPrivate::QProtobufPropertyOrdering *propertyOrdering() const
(since 6.8) QByteArray serialize(QAbstractProtobufSerializer *serializer) const
bool setProperty(QAnyStringView propertyName, const QVariant &value)
(since 6.6) bool setProperty(QAnyStringView propertyName, QVariant &&value)
(since 6.7) QList<QByteArray> unknownFieldData(qint32 field) const
(since 6.7) QList<qint32> unknownFieldNumbers() const

정적 공용 멤버

QProtobufMessagePointer constructByName(const QString &messageType)

보호된 함수

QProtobufMessage(QProtobufMessage &&other)
QProtobufMessagePointer
(since 6.11) To qprotobufmessage_cast(QProtobufMessage *from)
(since 6.11) To qprotobufmessage_cast(const QProtobufMessage *from)

상세 설명

setProperty() 및 property()를 사용하여 메시지가 무엇인지에 관계없이 메시지의 속성에 대한 액세스를 제공합니다.

멤버 함수 문서

[constexpr noexcept protected default] QProtobufMessage::QProtobufMessage(QProtobufMessage &&other)

QProtobufMessage 의 인스턴스를 move-construct로 생성합니다.

[static] QProtobufMessagePointer QProtobufMessage::constructByName(const QString &messageType)

messageType 를 사용하여 QProtobufMessage 를 생성합니다. 생성된 QProtobufMessage 에 대한 포인터를 반환합니다.

이 함수는 messageType 와 일치하는 유형을 가진 메시지를 생성하려고 시도합니다. messageType 가 알려지지 않은 경우, 함수는 nullptr 를 반환합니다. 레지스트리에서 메시지를 찾을 수 없는 경우, 함수는 nullptr 를 반환합니다. 생성된 메시지의 소유권은 함수 호출자에게 부여됩니다.

[since 6.8] bool QProtobufMessage::deserialize(QAbstractProtobufSerializer *serializer, QByteArrayView data)

QByteArray data 에서 이 프로토버프 메시지를 serializer 를 사용하여 역직렬화합니다. 역직렬화가 성공하면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다.

이 함수는 Qt 6.8에서 도입되었습니다.

serialize()도 참조하십시오 .

QVariant QProtobufMessage::property(QAnyStringView propertyName) const

propertyName 속성의 값을 가져옵니다.

propertyName 가 알려지지 않은 경우, 반환된 QVariant 는 유효하지 않습니다.

setProperty()도 참조하십시오 .

[since 6.8] const QtProtobufPrivate::QProtobufPropertyOrdering *QProtobufMessage::propertyOrdering() const

파생된 프로토버프 메시지의 속성 순서를 가리키는 포인터를 반환합니다.

이 함수는 Qt 6.8에서 도입되었습니다.

[since 6.8] QByteArray QProtobufMessage::serialize(QAbstractProtobufSerializer *serializer) const

serializer 를 사용하여 이 protobuf 메시지를 QByteArray 로 직렬화합니다.

이 함수는 Qt 6.8에서 도입되었습니다.

deserialize()도 참조하십시오 .

bool QProtobufMessage::setProperty(QAnyStringView propertyName, const QVariant &value)

propertyName 속성을 value 에 저장된 값으로 설정합니다.

propertyName 가 알려진 필드가 아닌 경우, 해당 값은 무시되고 함수는 false 를 반환합니다.

value 를 속성에 저장하는 데 실패하면 false 를 반환합니다. 그렇지 않으면 true 를 반환합니다.

property()도 참조하십시오 .

[since 6.6] bool QProtobufMessage::setProperty(QAnyStringView propertyName, QVariant &&value)

이 함수는 오버로드된 함수입니다.

이 함수는 Qt 6.6에서 도입되었습니다.

[since 6.7] QList<QByteArray> QProtobufMessage::unknownFieldData(qint32 field) const

네트워크를 통해 수신된 순서대로 정렬된 알 수 없는 ‘ field ’ 값들을 반환합니다.

이 함수는 Qt 6.7에서 도입되었습니다.

[since 6.7] QList<qint32> QProtobufMessage::unknownFieldNumbers() const

역직렬화 과정에서 ` QtProtobuf `가 인식하지 못한 필드 번호를 반환합니다.

이 함수는 Qt 6.7에서 도입되었습니다.

관련 비멤버

[alias] QProtobufMessagePointer

std::unique_ptr<QProtobufMessage, QProtobufMessageDeleter>의 동의어입니다. QProtobufMessage::constructByName 를 호출하여 생성된 것과 같이 동적으로 할당된 QProtobufMessage의 수명을 관리할 때 이 유형을 사용합니다.

[since 6.11] template <typename To> To qprotobufmessage_cast(QProtobufMessage *from)

[since 6.11] template <typename To> To qprotobufmessage_cast(const QProtobufMessage *from)

주어진 ` from ` 객체가 ` To `(또는 그 하위 클래스) 유형인 경우, 해당 객체를 ` To ` 포인터 유형으로 형변환하여 반환하고, 그렇지 않은 경우 ` nullptr`를 반환합니다. ` from `가 ` nullptr`인 경우, 이 함수는 ` nullptr`도 반환합니다.

템플릿 인자 ` To `는 ` QProtobufMessage `를 상속하고 ` Q_PROTOBUF_OBJECT ` 매크로로 선언된 클래스에 대한 포인터여야 합니다.

예시:

QProtobufMessage *message = new myproject::MySpecificMessage();

// Cast to its own type (success)
auto *specific = qprotobufmessage_cast<myproject::MySpecificMessage *>(message);
// specific is a valid pointer

// Cast to an unrelated type (failure)
auto *another = qprotobufmessage_cast<myproject::AnotherMessage *>(message);
// another is nullptr

이 함수는 표준 C++의 ` dynamic_cast()`와 유사하게 동작하며, RTTI 지원이 필요하지 않고 동적 라이브러리 경계를 넘어 작동한다는 장점이 있습니다.

경고: To 가 가리키는 유형이 Q_PROTOBUF_OBJECT 매크로를 사용하여 선언되지 않은경우 , 이 함수의 반환 값은 정의되지 않습니다.

이 함수들은 Qt 6.11에서 도입되었습니다.

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