QQmlSA::PassManager Class
class QQmlSA::PassManager可通过静态分析对元素及其子元素进行分析。更多
头文件: | #include <PassManager> |
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 。
© 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.