이 페이지에서

QProtobufMessage Class

모든 프로토부프 메시지의 베이스 클래스입니다. 더 보기...

헤더: #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)
QProtobufMessagePointer
(since 6.11) To qprotobufmessage_cast(QProtobufMessage *from)
(since 6.11) To qprotobufmessage_cast(const QProtobufMessage *from)

상세 설명

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

멤버 함수 문서

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

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

이 함수는 messageType 와 일치하는 타입의 메시지를 만들려고 시도합니다. messageType 을 알 수 없으면 nullptr 을 반환합니다. 레지스트리에서 메시지를 찾을 수 없으면 이 함수는 nullptr 을 반환합니다. 함수 호출자에게는 생성된 메시지의 소유권이 주어집니다.

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

serializer 를 사용하여 QByteArray data 에서 이 프로토뷰 메시지를 역직렬화합니다. 역직렬화에 성공하면 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 을 사용하여 이 프로토뷰 메시지를 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 을 반환합니다. fromnullptr 인 경우, 이 함수는 nullptr 도 반환합니다.

템플릿 인수 ToQProtobufMessage 에서 상속되고 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.