QObjectComputedProperty Class
template <typename Class, typename T, auto Offset, auto Getter> class QObjectComputedPropertyQObjectComputedProperty 클래스는 이전 프로퍼티를 바인딩 가능한 프로퍼티 시스템으로 포팅하는 데 도움이 되는 템플릿 클래스입니다. 더 보기...
Header: | #include <QObjectComputedProperty> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
이후: | Qt 6.0 |
상속합니다: | QUntypedPropertyData |
매크로
(since 6.0) | Q_OBJECT_COMPUTED_PROPERTY(containingClass, type, name, callback) |
상세 설명
QObjectComputedProperty는 읽을 때마다 다시 계산되는 읽기 전용 프로퍼티입니다. 계산된 값은 저장하지 않습니다. Qt 바인더블 프로퍼티를 구현하는 Qt 내부 클래스 중 하나입니다. QObjectComputedProperty는 일반적으로 직접 사용되지 않고 Q_OBJECT_COMPUTED_PROPERTY 매크로를 사용하여 인스턴스가 생성됩니다.
다음 예제를 참조하십시오.
class Client{}; class MyClassPrivate : public QObjectPrivate { public: QList<Client> clients; bool hasClientsActualCalculation() const { return clients.size() > 0; } Q_OBJECT_COMPUTED_PROPERTY(MyClassPrivate, bool, hasClientsData, &MyClassPrivate::hasClientsActualCalculation) }; class MyClass : public QObject { Q_OBJECT Q_PROPERTY(bool hasClients READ hasClients STORED false BINDABLE bindableHasClients) public: QBindable<bool> bindableHasClients() { return QBindable<bool>(&d_func()->hasClientsData); } bool hasClients() const { return d_func()->hasClientsData.value(); } void addClient(const Client &c) { Q_D(MyClass); d->clients.push_back(c); // notify that the value could have changed d->hasClientsData.notify(); } private: Q_DECLARE_PRIVATE(MyClass) };
바인더블 프로퍼티 게터 및 설정자의 게 터에 대한 규칙은 QObjectComputedProperty에도 적용됩니다. 특히, 게터는 단순해야 하며 QObjectComputedProperty 객체의 값만 반환해야 합니다. QObjectComputedProperty에 주어진 콜백은 일반적으로 QObjectComputedProperty에 의해서만 호출되는 비공개 메서드여야 합니다.
설정자는 필요하지 않거나 허용되지 않습니다. QObjectComputedProperty는 읽기 전용이므로.
종속성 처리에 올바르게 참여하려면 QObjectComputedProperty는 자신에게 주어진 콜백의 결과인 해당 값이 언제 변경될 수 있는지 알아야 합니다. 콜백에 사용되는 바인딩 가능한 프로퍼티가 변경될 때마다 이 작업이 자동으로 수행됩니다. 바인딩 가능한 프로퍼티가 아닌 값의 변경으로 인해 콜백의 결과가 변경될 수 있는 경우, 개발자는 QObjectComputedProperty 객체에서 notify
을 호출할 책임이 있습니다. 이렇게 하면 종속 프로퍼티에 잠재적인 변경 사항을 알릴 수 있습니다.
notify
을 호출하면 종속 프로퍼티의 변경 핸들러가 트리거될 수 있으며, 이 핸들러는 QObjectComputedProperty가 멤버로 있는 객체를 사용할 수 있다는 점에 유의하세요. 따라서 트랜지션 상태 또는 유효하지 않은 상태에서는 notify
을 호출해서는 안 됩니다.
QObjectComputedProperty는 파일 내용처럼 예고 없이 변경될 수 있는 입력에 의존하는 계산에 사용하기에 적합하지 않습니다.
Q_OBJECT_COMPUTED_PROPERTY, QProperty, QObjectBindableProperty, Qt의 프로퍼티 시스템 및 Qt 바인더블 프로퍼티를참조하십시오 .
매크로 문서
[since 6.0]
Q_OBJECT_COMPUTED_PROPERTY(containingClass, type, name, callback)
type 타입의 containingClass 안에 name 라는 이름의 QObjectComputedProperty 를 선언합니다. 인자 callback 는 프로퍼티가 평가될 때 호출할 GETTER 함수를 지정합니다.
이 매크로는 Qt 6.0에 도입되었습니다.
QObjectBindableProperty, Qt의 프로퍼티 시스템, Qt 바인더블 프로퍼티를참조하십시오 .
© 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.