このページでは

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コンストラクタで生成します。

[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 からこの Protobuf メッセージをデシリアライズします。デシリアライズに成功した場合は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 の呼び出しによって作成されるものなど、動的に割り当てられた QProtobufMessages のライフサイクルを管理するために使用します。

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