本页内容

QQmlSA::PassManager Class

class QQmlSA::PassManager

可通过静态分析步骤分析某个元素及其子元素。更多...

标题: #include <qqmlsa.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS QmlCompiler)
target_link_libraries(mytarget PRIVATE Qt6::QmlCompiler)
状态: 技术预览

该类处于技术预览阶段,内容可能会有变动。

公共函数

void analyze(const QQmlSA::Element &root)
std::unordered_map<quint32, QQmlSA::Binding> bindingsByLocation() const
bool hasImportedModule(QAnyStringView module) const
bool isCategoryEnabled(QQmlSA::LoggerWarningId category) const
void registerElementPass(std::unique_ptr<QQmlSA::ElementPass> pass)
bool registerPropertyPass(std::shared_ptr<QQmlSA::PropertyPass> pass, QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName = QAnyStringView(), bool allowInheritance = true)

详细说明

成员函数文档

void PassManager::analyze(const QQmlSA::Element &root)

对元素及其所有子元素执行root 。

std::unordered_map<quint32, QQmlSA::Binding> PassManager::bindingsByLocation() const

根据源位置返回绑定。

bool PassManager::hasImportedModule(QAnyStringView module) const

如果待分析的 QML 已导入名为module 的模块,则返回true ;否则返回false 。

这可用于跳过针对特定模块的处理阶段的注册。

if (passManager->hasImportedModule("QtPositioning"))
    passManager->registerElementPass(
       std::make_unique<PositioningPass>(passManager)
    );

另请参阅 registerPropertyPass() 和registerElementPass()。

bool PassManager::isCategoryEnabled(QQmlSA::LoggerWarningId category) const

如果启用了category 的警告,则返回true ;否则返回false 。

void PassManager::registerElementPass(std::unique_ptr<QQmlSA::ElementPass> pass)

注册一个静态分析pass ,用于对所有元素进行分析。

bool PassManager::registerPropertyPass(std::shared_ptr<QQmlSA::PropertyPass> pass, QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName = QAnyStringView(), bool allowInheritance = true)

注册一个针对属性的静态分析过程。pass 将对所有符合moduleName 、typeName 和propertyName 的属性进行运行。

若省略propertyName ,则会将此分析阶段注册为适用于所有符合typeName 和moduleName 条件的属性。

将allowInheritance 设置为true 意味着类型过滤条件也会接受继承自typeName 的类型。

pass 作为std::shared_ptr 传递,以便在多个元素上复用同一分析阶段:

auto titleValiadorPass = std::make_shared<TitleValidatorPass>(manager);
manager->registerPropertyPass(titleValidatorPass,
                              "QtQuick", "Window", "title");
manager->registerPropertyPass(titleValidatorPass,
                              "QtQuick.Controls", "Dialog", "title");

注意: 对过多项目运行 分析处理可能消耗大量资源。因此,通常建议使用moduleName 、typeName 和propertyName 对处理的属性集进行筛选。

若处理阶段添加成功,则返回true ;否则返回false 。当由moduleName 和typeName 指定的Element 不存在时,添加处理阶段将失败。

另请参阅 PropertyPass 。

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