QBindable Class
template <typename T> class QBindableQBindable은 바인딩이 가능한 속성을 감싸는 래퍼 클래스입니다. 이 클래스는 다양한 속성 클래스 간의 차이점을 추상화함으로써 유형 안전성을 보장하는 연산을 가능하게 합니다. 더 보기...
| 헤더: | #include <QBindable> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 상속: | QUntypedBindable |
공개 함수
(since 6.5) | QBindable(QObject *obj, const QMetaProperty &property) |
(since 6.5) | 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 가 속성 값의 유형을 지정하는 템플릿 클래스입니다.
QBindable<T>는 Qt의 기존 ` Q_PROPERTY `를 바인딩이 가능한 속성과 통합하는 데 도움을 줍니다. 프로퍼티가 ` QProperty`, ` QObjectBindableProperty ` 또는 ` QObjectComputedProperty`로 뒷받침되는 경우, ` Q_PROPERTY ` 선언에 ` BINDABLE bindablePropertyName`을 추가할 수 있습니다. 여기서 `bindablePropertyName`은 ` QProperty`에서 생성된 `QBindable` 인스턴스를 반환하는 함수입니다. 반환된 `QBindable`을 통해 프로퍼티 사용자는 사용된 바인딩 지원 프로퍼티의 정확한 종류를 알 필요 없이 프로퍼티의 바인딩을 설정하고 조회할 수 있습니다.
class MyClass : public 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 84QMetaProperty::isBindable, QProperty, QObjectBindableProperty, QObjectComputedProperty 및 Qt 바인딩 가능한 속성도참조하십시오 .
멤버 함수 문서
[explicit, since 6.5] QBindable::QBindable(QObject *obj, const QMetaProperty &property)
QBindable::QBindable(QObject *obj, const char *property) 참조
이 함수는 Qt 6.5에서 도입되었습니다.
[explicit, since 6.5] 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 에 대한 BINDABLE 를 구현하는 데 사용해서는 안 됩니다. 그 결과 생성된 Q_PROPERTY 는 종속성 추적을 지원하지 않기 때문입니다. QBindable을 거치지 않고 직접 사용할 수 있는 속성을 만들려면 QProperty 또는 QObjectBindableProperty 를 사용하십시오.
QProperty<QString> displayText;
QDateTimeEdit *dateTimeEdit = findDateTimeEdit();
QBindable<QDateTime> dateTimeBindable(dateTimeEdit, "dateTime");
displayText.setBinding([dateTimeBindable](){ return dateTimeBindable.value().toString(); });이 함수는 Qt 6.5에서 도입되었습니다.
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 가 읽기 전용이거나 유효하지 않은 경우 아무 작업도 수행하지 않습니다.
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 `가 반환됩니다.
© 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.