QObjectComputedProperty Class
template <typename Class, typename T, auto Offset, auto Getter> class QObjectComputedPropertyQObjectComputedProperty 클래스는 기존 속성을 바인딩 가능한 속성 시스템으로 이식하는 데 도움을 주는 템플릿 클래스입니다. 더 보기...
| 헤더: | #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는 템플릿 클래스로, 템플릿 매개변수 Class 는 소유 클래스인 QObject 의 파생 클래스를 지정하고, T 는 계산된 속성 값의 유형을 지정하며, Offset 는 클래스 내 속성의 위치를 지정하고, Getter 는 속성 값을 계산하는 멤버 함수를 지정합니다.
QObjectComputedProperty는 읽을 때마다 재계산되는 읽기 전용 속성입니다. 이 클래스는 계산된 값을 저장하지 않습니다. 이는 Qt Bindable Properties를 구현하는 Qt 내부 클래스 중 하나입니다. QObjectComputedProperty는 일반적으로 직접 사용되지 않으며, 대신 Q_OBJECT_COMPUTED_PROPERTY 매크로를 사용하여 인스턴스를 생성합니다.
다음 예제를 참조하십시오.
class Client{};
class MyClassPrivate : public QObject
{
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 바인딩 가능한 속성도참조하십시오 .
멤버 함수 문서
[default] QObjectComputedProperty::QObjectComputedProperty()
QObjectComputedProperty 의 인스턴스를 기본 생성합니다.
매크로 설명서
[since 6.0] Q_OBJECT_COMPUTED_PROPERTY(containingClass, type, name, callback)
containingClass 내부에 type 타입의 QObjectComputedProperty 를 name 라는 이름으로 선언합니다. 인자 callback 는 속성이 평가될 때 호출될 GETTER 함수를 지정합니다.
이 매크로는 Qt 6.0에서 도입되었습니다.
QObjectBindableProperty, Qt의 속성 시스템( Property System), Qt 바인딩 가능 속성(Bindable Properties)도 참조하십시오 .
© 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.