Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtqmlcompiler-index.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qtqmlcompiler-index.html
6 \title Qt QML Compiler
7 \brief Provides tools for static analysis of QML code.
8
9 The Qt QML Compiler module contains shared functionality needed by QML
10 tooling like the \l{Qt Quick Compiler} and \l{qmllint Reference}{qmllint}.
11 It also provides the QQmlSA framework, which can be used to extend the
12 built-in analysis capabilities of the tools.
13
14 \section1 Using the Module
15
16 \include {module-use.qdocinc} {using the c++ api}
17
18 \section2 Building with CMake
19
20 \include {module-use.qdocinc} {building with cmake} {QmlCompiler}
21
22 \section2 Building with qmake
23
24 \include {module-use.qdocinc} {building_with_qmake} {QmlCompiler}
25
26 \section1 Using the QQmlSA framework
27
28 The Qt QML Compiler module offers the QQmlSA framework which provides tools
29 for static analysis of QML code. These tools can help ensure syntactic
30 validity and warn about QML anti-patterns.
31 Adding static analysis to a QML program is done by writing plugins. They
32 will run a collection of analysis passes over the elements and properties
33 of the QML code. The passes can be registered with a PassManager which
34 holds the passes and can be called to analyze an element and its children.
35 A pass is a check for a certain rule or condition evaluated on elements or
36 properties. If the condition is met, the pass can warn the user of an
37 indentified issue in the code and maybe even suggest a fix. It is called a
38 pass because the analysis performed on elements and properties happens by
39 running a collection of passes on them in succesion. Each pass should be
40 responsible for identifying one specific issue only. Combining a set of
41 passes can perform more complex analysis and, together, form a plugin.
42 Element passes are defined by two main components, namely \c shouldRun()
43 and \c run(). When performing the analysis, the pass manager will execute
44 the pass over every element it encounters while traversing the children of
45 the root element. For each element, if \c shouldRun() evaluated on that
46 element returns \c true then \c run() is executed on it.
47 Passes on properties trigger on three different events, namely when the
48 property is bound, when it is read, and when it is written to. These can be
49 implemented by overriding the \c onBinding(), \c onRead() and \c onWrite()
50 functions respectively.
51 As the code grows, so does the number of elements and properties.
52 Performing the static analysis passes on all of them can become expensive.
53 That's why it is good to be granular when deciding which elements and
54 properties to analyze. For elements, the \c shouldRun() is intended to be a
55 cheap check to determine if \c run(), which performs the real computation,
56 should be run. For properties, the selection is done when registering the
57 passes with the manager. The \c registerPropertyPass() function takes the
58 \c moduleName, \c typeName and \c propertyName strings as arguments. These
59 are used to filter down the set of properties affected by the registered
60 pass.
61
62
63 \section1 Examples
64
65 The \l{QML Static Analysis Tutorial} shows how to use the \c{QQmlSA}
66 framework to create a custom \l{qmllint Reference}{qmllint} pass.
67
68 \section1 Reference
69
70 \list
71 \li \l {Qt QML Compiler C++ Classes}
72 - the C++ API provided by the QmlCompiler module
73 \li QML tooling using the static analysis capabilities
74 \list
75 \li \l{QML script compiler}
76 \li \l{qmllint Reference}{qmllint}
77 \li \l{\QMLLS Reference}{\QMLLS}
78 \li \l{QML type compiler}
79 \endlist
80 \endlist
81 */