このページでは

QQmlSA::ElementPass Class

class QQmlSA::ElementPass

要素に対するすべての静的解析パスの基底クラスです。詳細...

ヘッダー: #include <qqmlsa.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS QmlCompiler)
target_link_libraries(mytarget PRIVATE Qt6::QmlCompiler)
継承元: QQmlSA::GenericPass
ステータス: テクノロジープレビュー

このクラスはテクノロジープレビュー段階にあり、変更される可能性があります。

パブリック関数

ElementPass(QQmlSA::PassManager *manager)
virtual void run(const QQmlSA::Element &element) = 0
virtual bool shouldRun(const QQmlSA::Element &element)

詳細な説明

ElementPass は、2 つの分析パスのうち、より単純なものです。ファイル内のすべての要素を対象とします。shouldRun() メソッドを使用して、無関係な要素を除外することができ、run() メソッドが初期処理を行います。

ElementPass に適した一般的なタスクは次のとおりです。

  • 要素のプロパティが、意味をなさない方法で組み合わされていないことの確認
  • プロパティ値の検証(例:プロパティが特定の列挙型の値のみを取るなど)
  • Elementの親要素に依存する挙動のチェック(例:親要素がLayout である場合にItem::width を使用しないなど)。

以下のスニペットに示すように、静的解析のパフォーマンスを維持するために、ElementPassのコンストラクタ内で必要な型解決を行い、それをローカルメンバーにキャッシュし、shouldRun() によるフィルタリングを実装することを推奨します。

using namespace QQmlSA;
class MyElementPass : public ElementPass
{
    Element myType;
    public:
        MyElementPass(QQmlSA::PassManager *manager)
        : myType(resolveType("MyModule", "MyType")) {}

        bool shouldRun(const Element &element) override
        {
            return element.inherits(myType);
        }
        void run(const Element &element) override
        {
            // actual pass logic
        }
}

ElementPassでは、要素のプロパティがどのように使用されているかについて把握できる範囲は限られています。その情報が必要な場合は、代わりにPropertyPass の使用を検討してください。

注:ElementPassは インスタンス化可能な型のみを対象とします。したがって、アタッチされた型やシングルトンの解析には適していません。これらについては、PropertyPass を使用して処理する必要があります。

メンバ関数のドキュメント

ElementPass::ElementPass(QQmlSA::PassManager *manager)

ElementPass オブジェクトを作成し、manager を使用してパスマネージャーを参照します。

[pure virtual] void ElementPass::run(const QQmlSA::Element &element)

shouldRun() がtrue を返した場合に実行されます。element に対して、パスの実際の計算を実行します。このメソッドはオーバーライドされることを想定しています。基底メソッドを呼び出す必要はありません。

[virtual] bool ElementPass::shouldRun(const QQmlSA::Element &element)

指定されたelement に対してrun() 関数を実行するかどうかを制御します。サブクラスはこのメソッドをオーバーライドし、関連性のない要素を除外することで、分析のパフォーマンスを向上させることができます。

デフォルトの実装では、無条件にtrue を返します。

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