이 페이지에서

QQmlParserStatus Class

QQmlParserStatus 클래스는 QML 파서 상태에 대한 최신 정보를 제공합니다. 더 보기...

헤더: #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()

이 인스턴스화를 유발한 루트 컴포넌트의 생성이 완료된 후에 호출됩니다. 이 시점에서는 모든 정적 값과 바인딩 값이 클래스에 할당된 상태입니다.

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