QProtobufMessage Class

Base class for all protobuf messages. More...

Header: #include <QProtobufMessage>
CMake: find_package(Qt6 REQUIRED COMPONENTS Protobuf)
target_link_libraries(mytarget PRIVATE Qt6::Protobuf)
Since: Qt 6.5

Public Functions

(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

Static Public Members

QProtobufMessagePointer constructByName(const QString &messageType)

Detailed Description

Provides access to the properties of a message, using setProperty() and property(), without depending on what the message is.

Member Function Documentation

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

Constructs QProtobufMessage using messageType. Returns a pointer to the constructed QProtobufMessage.

This function attempts to create a message with a type that matches messageType. If messageType is unknown, the function returns nullptr. If the message is not found in the registry, the function returns nullptr. The function caller is given ownership of the constructed message.

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

Deserializes this protobuf message from a QByteArray data using serializer. Returns true if deserialization was successful, otherwise false.

This function was introduced in Qt 6.8.

See also serialize().

QVariant QProtobufMessage::property(QAnyStringView propertyName) const

Get the value of the property propertyName.

If the propertyName isn't known then the returned QVariant is invalid.

See also setProperty().

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

Returns the pointer to the property ordering of the derived protobuf message.

This function was introduced in Qt 6.8.

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

Serializes this protobuf message into a QByteArray using serializer.

This function was introduced in Qt 6.8.

See also deserialize().

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

Set the property propertyName to the value stored in value.

If the propertyName isn't a known fields, then the value is ignored, and the function returns false.

Returns false if it fails to store the value on the property. Otherwise true.

See also property().

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

This is an overloaded function.

This function was introduced in Qt 6.6.

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

Returns the unknown field values sorted as they were received from the wire.

This function was introduced in Qt 6.7.

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

Returns the field numbers that were not known to QtProtobuf during deserialization.

This function was introduced in Qt 6.7.

Related Non-Members

[alias] QProtobufMessagePointer

Synonym for std::unique_ptr<QProtobufMessage, QProtobufMessageDeleter>. Use this to manage the lifetime of dynamically allocated QProtobufMessages, such as those created by calling QProtobufMessage::constructByName.