QBindable Class

template <typename T> class QBindable

QBindable은 바인딩이 가능한 프로퍼티를 둘러싼 래퍼 클래스입니다. 다양한 프로퍼티 클래스 간의 차이점을 추상화하면서 유형 안전 연산을 가능하게 합니다. 더 보기...

Header: #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 클래스: 공용 QObject
{ Q_OBJECT Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged BINDABLE bindableX)public: int x() const { return xProp; } void setX(int x) { xProp = x; } QBindable<int> bindableX() { return QBindable<int>(&xProp); }signals: void xChanged();private: // 바인더블 프로퍼티 데이터의 인스턴스를 선언합니다.Q_OBJECT_BINDABLE_PROPERTY(MyClass, int, xProp, &MyClass::xChanged) }; MyClass *myObject;QBindable<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 *객체, const char *프로퍼티)를 참조하십시오.

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

obj 에서 Q_PROPERTY property 에 대한 QBindable을 구축합니다. 이 프로퍼티에는 알림 신호가 있어야 하지만 Q_PROPERTY 정의에 BINDABLE 가 있을 필요는 없으므로 인식하지 못하는 Q_PROPERTY도 바인딩하거나 바인딩 표현식에 사용할 수 있습니다. 속성이 BINDABLE 이 아닌 경우 종속성 추적을 활성화하려면 일반 속성 READ 함수(또는 MEMBER) 대신 바인딩 표현식에 QBindable::value() 을 사용해야 합니다. 람다를 사용하여 바인딩하는 경우, 바인딩 표현식에서 이 생성자를 호출하는 데 드는 비용을 피하기 위해 QBindable을 값으로 캡처하는 것이 더 좋을 수 있습니다. 이 생성자는 Q_PROPERTY 에 대해 BINDABLE 을 구현하는 데 사용해서는 안 되며, 그 결과 Q_PROPERTY 는 종속성 추적을 지원하지 않습니다. QBindable을 읽지 않고 바로 사용할 수 있는 프로퍼티를 만들려면 QProperty 또는 QObjectBindableProperty 을 사용하세요.

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

QProperty, QObjectBindablePropertyQt XML 바인더블 프로퍼티도참조하십시오 .

QPropertyBinding<T> QBindable::binding() const

현재 설정된 기본 속성의 바인딩을 반환합니다. 속성에 바인딩이 없는 경우 반환된 QPropertyBinding<T> 은 유효하지 않습니다.

setBindinghasBinding도 참조하세요 .

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

지정된 소스를 사용하여 기본 프로퍼티의 값을 평가하는 바인딩을 구성합니다 location.

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

기본 속성의 바인딩을 binding 으로 설정합니다. QBindable 이 읽기 전용이거나 유효하지 않은 경우 아무 작업도 수행하지 않습니다.

binding, isReadOnly() 및 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> 은 유효하지 않습니다.

binding, setBinding, 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.