QProtobufMessage Class
すべてのprotobufメッセージの基本クラス。さらに...
| ヘッダー | #include <QProtobufMessage> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Protobuf)target_link_libraries(mytarget PRIVATE Qt6::Protobuf) |
| 以来: | Qt 6.5 |
| 継承元 |
パブリック関数
(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)
この protobuf メッセージを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
派生した protobuf メッセージのプロパティ順序へのポインタを返します。
この関数は Qt 6.8 で導入されました。
[since 6.8] QByteArray QProtobufMessage::serialize(QAbstractProtobufSerializer *serializer) const
この protobuf メッセージを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 を呼び出して作成されるような、動的に割り当てられる QProtobufMessages の寿命を管理するために使用します。
[since 6.11] template <typename To> To qprotobufmessage_cast(QProtobufMessage *from)
[since 6.11] template <typename To> To qprotobufmessage_cast(const QProtobufMessage *from)
nullptr与えられたfrom オブジェクトがTo 型(またはサブクラス)である場合、ポインタ型To にキャストして返します。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.