QQmlParserStatus Class

QQmlParserStatus 클래스는 QML 구문 분석기 상태에 대한 업데이트를 제공합니다. 더 보기...

Header: #include <QQmlParserStatus>
CMake: find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake: QT += qml
상속 대상:

QQuickItem

공용 함수

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;
};

멤버 함수 문서

[pure virtual] void QQmlParserStatus::classBegin()

클래스 생성 후 프로퍼티가 설정되기 전에 호출됩니다.

[pure virtual] void QQmlParserStatus::componentComplete()

이 인스턴스화를 일으킨 루트 컴포넌트가 구성을 완료한 후에 호출됩니다. 이 시점에서 모든 정적 값과 바인딩 값이 클래스에 할당됩니다.

© 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.