QQmlListProperty Class
template <typename T> class QQmlListPropertyQQmlListProperty クラスは、QObject から派生したクラスのリストのようなプロパティを QML に公開するためのクラスです。さらに...
ヘッダ | #include <QQmlListProperty> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml) target_link_libraries(mytarget PRIVATE Qt6::Qml) |
qmake: | QT += qml |
パブリックな型
パブリック関数
QQmlListProperty(QObject *object, QList<T *> *list) | |
QQmlListProperty(QObject *object, void *data, QQmlListProperty<T>::CountFunction count, QQmlListProperty<T>::AtFunction at) | |
QQmlListProperty(QObject *object, void *data, QQmlListProperty<T>::AppendFunction append, QQmlListProperty<T>::CountFunction count, QQmlListProperty<T>::AtFunction at, QQmlListProperty<T>::ClearFunction clear) | |
QQmlListProperty(QObject *object, void *data, QQmlListProperty<T>::AppendFunction append, QQmlListProperty<T>::CountFunction count, QQmlListProperty<T>::AtFunction at, QQmlListProperty<T>::ClearFunction clear, QQmlListProperty<T>::ReplaceFunction replace, QQmlListProperty<T>::RemoveLastFunction removeLast) | |
bool | operator==(const QQmlListProperty<T> &other) const |
マクロ
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND | |
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE | |
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT |
詳細説明
QMLには多くのリストプロパティがあり、複数のオブジェクトの値を代入する ことができます。QMLのリストプロパティの使い方は次のようになります:
FruitBasket { fruit: [ Apple {}, Orange{}, Banana{} ] }
QQmlListPropertyは、QMLがリストに対して実行できる一連の操作(項目の追加、項目の取得、リストのクリア)を表す関数ポインタ群をカプセル化したものです。将来的には、さらなる操作がサポートされるかもしれません。全てのリストプロパティは append 操作を実装しなければなりませんが、それ以外はオプションです。
リストプロパティを提供するには、C++クラスは操作コールバックを実装し、プロパティゲッターから適切なQQmlListProperty値を返す必要があります。リスト・プロパティはセッターを持つべきではありません。上の例では、Q_PROPERTY() 宣言文は次のようになります:
Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit)
QMLのリスト・プロパティは型安全です。この場合、Fruit
はQObject の型であり、Apple
、Orange
、Banana
はすべてこの型から派生しています。
第5章 リストプロパティ型の使用も参照してください 。
メンバ型のドキュメント
[alias]
QQmlListProperty::AppendFunction
void (*)(QQmlListProperty<T> *property, T *value)
の同義語。
value をリストproperty に追加する。
[alias]
QQmlListProperty::AtFunction
T *(*)(QQmlListProperty<T> *property, qsizetype index)
の同義語。
リストproperty の位置index にある要素を返す。
[alias]
QQmlListProperty::ClearFunction
の類義語void (*)(QQmlListProperty<T> *property)
.
リストをクリアproperty.
[alias]
QQmlListProperty::CountFunction
qsizetype (*)(QQmlListProperty<T> *property)
の同義語。
リストの要素数を返すproperty.
[alias]
QQmlListProperty::RemoveLastFunction
void (*)(QQmlListProperty<T> *property)
の同義語。
リストから最後の要素を削除するproperty.
[alias]
QQmlListProperty::ReplaceFunction
void (*)(QQmlListProperty<T> *property, qsizetype index, T *value)
の同義語。
リストproperty の位置index にある要素をvalue で置き換える。
メンバ関数ドキュメント
QQmlListProperty::QQmlListProperty(QObject *object, QList<T *> *list)
既存のQList list から QQmlListProperty の値を作るための便利なコンストラクタです。object が存在する限り、list の参照は有効でなければなりません。object を指定する必要があります。
QQmlListProperty::QQmlListProperty(QObject *object, void *data, QQmlListProperty<T>::CountFunction count, QQmlListProperty<T>::AtFunction at)
読み取り専用の QQmlListProperty を、一連の操作関数count とat から構築します。操作関数内からアクセスできる不透明なdata ハンドルを渡すことができます。リストプロパティは、object が存在する限り有効です。
QQmlListProperty::QQmlListProperty(QObject *object, void *data, QQmlListProperty<T>::AppendFunction append, QQmlListProperty<T>::CountFunction count, QQmlListProperty<T>::AtFunction at, QQmlListProperty<T>::ClearFunction clear)
append,count,at,clear の操作関数群から QQmlListProperty を構築します。不透明なdata ハンドルが渡され、操作関数内からアクセスすることができます。リスト・プロパティは、object が存在する限り有効である。
どの関数に対してもヌル・ポインタを渡すことができる。NULLポインタが渡された場合、リストはデバッガによって設計も変更もできなくなります。すべての関数に対して有効なポインタを指定することをお勧めします。
注意: 結果として得られる QQmlListProperty は、removeLast() メソッドと replace() メソッドを、count,at,clear,append を使って合成します。これは遅い。リストをクリアする以上の操作を行う場合は、これらのメソッドを明示的に指定する必要があります。
QQmlListProperty::QQmlListProperty(QObject *object, void *data, QQmlListProperty<T>::AppendFunction append, QQmlListProperty<T>::CountFunction count, QQmlListProperty<T>::AtFunction at, QQmlListProperty<T>::ClearFunction clear, QQmlListProperty<T>::ReplaceFunction replace, QQmlListProperty<T>::RemoveLastFunction removeLast)
append,count,at,clear,replace, removeLast の操作関数のセットから QQmlListProperty を構築します。操作関数内からアクセスできる不透明なdata ハンドルを渡すことができます。リスト・プロパティは、object が存在する限り有効である。
どの関数に対しても Null ポインタを渡すことができ、可能であれば、その関数は他の関数を使用して合成されます。QQmlListPropertyは、。
- clear count とremoveLast
- replace count, , , およびat clear append
- replace using , , , およびcount at removeLast append
- removeLast count, , , およびat clear append
を使うことができる。これは低速だが、もしあなたのリストがこれらのプリミティブに対してネイティブに高速なオプションを提供していない場合、合成されたものを使いたいかもしれない。
さらに、count 、at 、append 、clear のいずれかが明示的に与えられても合成されてもいない場合、リストはデバッガによって設計も変更もできません。このような事態を避けるため、十分な有効ポインタを提供することを推奨します。
bool QQmlListProperty::operator==(const QQmlListProperty<T> &other) const
このQQmlListProperty がother と等しければ真を、そうでなければ偽を返す。
マクロ・ドキュメント
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND
このマクロは、このクラスのリストプロパティの動作を Append に定義します。派生型のプロパティを代入すると、値は基底クラスのものに追加されます。これはデフォルトの動作です。
class FruitBasket : QObject { Q_OBJECT QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit) public: // ... QQmlListProperty<Fruit> fruit(); // ... };
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT 、QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE 、およびQML 文書によるオブジェクト型の定義も参照してください 。
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE
このマクロは、このクラスのリストプロパティの Replace に対する動作を定義します。派生型にプロパティを代入すると、値は基底クラスのものを置き換えます。
class FruitBasket : QObject { Q_OBJECT QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit) public: // ... QQmlListProperty<Fruit> fruit(); // ... };
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND 、QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT 、QMLドキュメントによるオブジェクト型の定義も参照してください 。
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT
このマクロは、このクラスのリストプロパティの動作を ReplaceIfNotDefault に定義します。派生型のプロパティを代入すると、デフォルト・プロパティでない限り、値は基底クラスのものに置き換わります。デフォルト・プロパティの場合、値はベース・クラスのものに追加されます。
class FruitBasket : QObject { Q_OBJECT QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE_IF_NOT_DEFAULT Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit) public: // ... QQmlListProperty<Fruit> fruit(); // ... };
QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_APPEND 、QML_LIST_PROPERTY_ASSIGN_BEHAVIOR_REPLACE 、QMLドキュメントによるオブジェクト型の定義も参照してください 。
© 2025 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.