QBindable Class

template <typename T> class QBindable

QBindableは、バインディング可能なプロパティのラッパー・クラスです。様々なプロパティ・クラス間の違いを抽象化しながら、型安全な操作を可能にします。詳細...

ヘッダー #include <QBindable>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
を継承する: QUntypedBindable

パブリック関数

QBindable(QObject *obj, const QMetaProperty &property)
QBindable(QObject *obj, const char *property)
QPropertyBinding<T> binding() const
QPropertyBinding<T> makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) const
QPropertyBinding<T> setBinding(const QPropertyBinding<T> &binding)
QPropertyBinding<T> setBinding(Functor f)
void setValue(const T &value)
QPropertyBinding<T> takeBinding()
T value() const

詳細説明

QBindable<T> は、Qt の伝統的なQ_PROPERTYバインディング可能なプロパティを統合するのに役立ちます。プロパティがQProperty,QObjectBindableProperty,QObjectComputedProperty でサポートされている場合、Q_PROPERTY の宣言にBINDABLE bindablePropertyName を追加することができます。bindablePropertyName は、QProperty から構築された QBindable のインスタンスを返す関数です。返された QBindable により、プロパティのユーザーは、使用されているバインディング可能プロパティの正確な種類を知らなくても、プロパティのバインディングを設定したり、クエリしたりすることができます。

クラスMyClass :publicQObject
{ Q_OBJECT Q_PROPERTY(intx READ x WRITE setX NOTIFY xChanged BINDABLE bindableX)public:intx()const{returnxProp; }voidsetX(intx) { xProp=x; } }.  QBindable<int>bindableX() {returnQBindable<int>(&xProp); }signals:voidxChanged();private:// バインド可能なプロパティデータのインスタンスを宣言します。Q_OBJECT_BINDABLE_PROPERTY(MyClass, int,xProp, &MyClass::xChanged) }; MyClass*myObjectQBindable<int>bindableX=  myObject->bindableX();qDebug() << bindableX.hasBinding(); // prints false
QProperty<int>y{42}; bindableX.setBinding([&](){return  2*y.value(); });qDebug() << bindableX.hasBinding() << myObject->x(); // prints true 84

QMetaProperty::isBindable,QProperty,QObjectBindableProperty,QObjectComputedProperty,Qt Bindable Propertiesも参照してください

メンバ関数のドキュメント

[explicit] QBindable::QBindable(QObject *obj, const QMetaProperty &property)

QBindable::QBindable(QObject *obj, const char *property)を参照。

[explicit] QBindable::QBindable(QObject *obj, const char *property)

obj 上のQ_PROPERTY property の QBindable を構築します。こ のプ ロ パテ ィ は notify シグナルを持つ必要があ り ますが、Q_PROPERTY 定義にBINDABLE を持つ必要はないので、 バ イ ンデ ィ ン グ未承認のQ_PROPERTYもバ イ ンデ ィ ン グ可能、 ま たはバ イ ンデ ィ ン グ式で使用可能です。バインディング式では、プロパティがBINDABLE でない場合に依存性追跡を有効にするために、通常のプロパティREAD 関数(またはMEMBER )の代わりにQBindable::value() を使用する必要があります。ラムダを使用してバインディングする場合、バインディング式でこのコンストラクタを呼び出すコストを避けるために、QBindableを値でキャプチャすることを好むかもしれません。Q_PROPERTY このコンストラクタは、Q_PROPERTY に対してBINDABLE を実装するために使用すべきではありません。QBindable を通さずに直接使用できるプロパティを作成するには、QProperty またはQObjectBindableProperty を使用してください。

QProperty<QString> displayText;
QDateTimeEdit *dateTimeEdit = findDateTimeEdit();
QBindable<QDateTime> dateTimeBindable(dateTimeEdit, "dateTime");
displayText.setBinding([dateTimeBindable](){ return dateTimeBindable.value().toString(); });

QProperty,QObjectBindableProperty,Qt Bindable Propertiesも参照してください

QPropertyBinding<T> QBindable::binding() const

基礎となるプロパティの現在設定されているバインディングを返します。そのプロパティにバインディングがない場合、返されるQPropertyBinding<T> は無効です。

setBinding およびhasBindingも参照してください

QPropertyBinding<T> QBindable::makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) const

指定 さ れた ソ ースlocation を使用 し て、 基底プ ロ パテ ィ の値を評価す る バ イ ンデ ィ ン グ を構築 し ます。

QPropertyBinding<T> QBindable::setBinding(const QPropertyBinding<T> &binding)

基礎となるプロパティのバインディングをbinding に設定します。QBindable が読み取り専用または無効な場合は何も行いません。

bindingisReadOnly()、およびisValid()も参照してください

template <typename Functor> QPropertyBinding<T> QBindable::setBinding(Functor f)

これはオーバーロードされた関数です。

f からQPropertyBinding<T> を作成し、それをプロパティのバインディングとして設定します。

void QBindable::setValue(const T &value)

基礎となるプロパティの値をvalue に設定します。 これにより、現在設定されているバインディングがすべて削除されます。この関数は、QBindable が読み取り専用または無効な場合、何の効果も持ちません。

value()、isValid()、isReadOnly() およびsetBinding()も参照してください

QPropertyBinding<T> QBindable::takeBinding()

基礎となるプロパティの現在設定されているバインディングを削除し、それを返します。プロパティにバインディングがない場合、返されるQPropertyBinding<T> は無効です。

bindingsetBinding 、およびhasBindingも参照してください

T QBindable::value() const

プロパティの現在値を返す。QBindable が無効な場合は、デフォルトで構築されたT が返されます。

setValue() およびisValid()も参照

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