QQmlParserStatus Class
QQmlParserStatus 클래스는 QML 파서 상태에 대한 최신 정보를 제공합니다. 더 보기...
| 헤더: | #include <QQmlParserStatus> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml) target_link_libraries(mytarget PRIVATE Qt6::Qml) |
| qmake: | QT += qml |
| 상속된 항목: |
공개 함수
| virtual void | classBegin() = 0 |
| virtual void | componentComplete() = 0 |
상세 설명
QQmlParserStatus는 ` QQmlEngine `에 의해 인스턴스화된 클래스가 생성 과정의 주요 시점에서 알림을 수신할 수 있는 메커니즘을 제공합니다.
이 클래스는 객체의 모든 속성이 설정된 후에야 비용이 많이 드는 작업을 연기할 수 있게 해주므로, 최적화 목적으로 자주 사용됩니다. 예를 들어, QML의 Text 요소는 파서 상태를 사용하여 모든 속성이 설정될 때까지 텍스트 레이아웃을 연기합니다( text 가 할당될 때 레이아웃을 하고, font 가 할당될 때 다시 레이아웃을 하고, width 가 할당될 때 또 다시 레이아웃을 하는 등의 상황을 피하기 위함입니다).
QQmlParserStatus 메서드는 QQmlEngine 에 의해 클래스가 인스턴스화될 때만 호출된다는 점에 유의하십시오. C++에서 직접 동일한 클래스를 생성하는 경우, 이러한 메서드는 자동으로 호출되지 않습니다. 이 문제를 방지하려면, 클래스의 초기 생성 시점이 아닌 classBegin 에서 작업을 지연시키는 것을 권장합니다. 이렇게 하면 QML에서 초기 바인딩 할당 시 여러 번의 재평가가 발생하는 것을 여전히 방지할 수 있지만, C++에서 호출되는 작업은 지연되지 않습니다.
QQmlParserStatus를 사용하려면 QObject 에서 파생된 클래스와 QQmlParserStatus를 모두 상속받아야 하며, Q_INTERFACES() 매크로를 사용해야 합니다.
class MyObject : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
public:
MyObject(QObject *parent = nullptr);
// ...
void classBegin() override;
void componentComplete() override;
};© 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.