aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/qmllint/import.qdoc
blob: c5adababc45a1cd373d8bd5cd6a2ed50ea2a4cd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qmllint-warnings-and-errors-import.html
\ingroup qmllint-warnings-and-errors

\title Warnings Occurred While Importing
\brief The imported module was not found.

This warning category contains multiple warnings:
\list
\li \l{Failed To Import Module}
\li \l{Component Was Not Found}
\li \l{Import Qualifier Must Start With A Capital Letter}
\li \l{Unknown Import Syntax}
\endlist

\section1 Failed To Import Module

\section2 What happened?
The module imported via \l{Import Statements}{import statement} was not found.

This can be caused, for example, by
\list
    \li a typo in the import statement, or
    \li a user-defined module that was not built, or
    \li a wrong \l{Import Statements#qml-import-path}{import path}, or
    \li a missing module
\endlist

\section2 Why is this bad?
The application can't run because it can't find a module it relies on.

\section2 Examples

\section3 Typo In The Import Statement
\qml
import QtQuicky // not ok: typo in module name

Item {
}
\endqml
You can fix this warning by correcting the typo:
\qml
import QtQuick // ok: no typo in module name

Item {
}
\endqml

\section3 User-Defined Module That Was Not Built

Some tooling like \l{\QMLLS Reference}{\QMLLS} or \l{qmllint Reference}{qmllint}
can't find user-defined modules when they
are not built. If your project defines the QML Module you are trying to import, then
the QML tooling will not find it until you build it.

\note If building the module does not help when using \l{\QMLLS Reference}{\QMLLS}, follow the
instructions in
\l{Setting up the \QMLLS in Your Editor}{\QMLLS setup instructions}
and make sure that you communicate the correct build folder to \QMLLS.

\section3 Wrong Import Path

Please refer to \l{Import Statements#qml-import-path}{the QML import path documentation} and to
\l{Debugging QML Applications#debugging-module-imports}{the debugging module import documentation}
for more information about import paths.

\section3 Missing Module

If the previous sections did not help to find the imported module, it might be missing.
This might be caused by a missing dependency. When using external libraries, verify that they are
actually installed, and that their modules end up in an
\l{Import Statements#qml-import-path}{import path}.

\section1 Component Was Not Found

\section2 What happened?
Some component was not found.

\section2 Why is this bad?
The application can't run because it can't instantiate the non-found component.

\section2 Examples

\section3 Typo In The Component Name
\qml
import QtQuick

Item {
    Itemy {} // not ok: typo in name
}
\endqml
You can fix this warning by correcting the typo:
\qml
import QtQuick

Item {
    Item {} // ok: no typo in name
}
\endqml

\section3 Missing Import Statement

\qml

Item { // not ok: must be imported from QtQuick first
}
\endqml
You can fix this warning by adding the missing module import:
\qml
import QtQuick

Item { // ok: was imported from QtQuick
}
\endqml

\section1 Import Qualifier must start with a capital letter

\section2 What happened?
Some imported module has an invalid qualifier.

\section2 Why is this bad?
The module imported with this invalid qualifier can't be used.

\section2 Examples

\qml
import QtQuick as qq

qq.Item {
}
\endqml
You can fix this warning by making the import qualifier start with an upper case letter:
\qml
import QtQuick as Qq

Qq.Item {
}
\endqml

\section1 Unknown Import Syntax

\section2 What happened?
An import statement is using an invalid \l{Import Statements}{import syntax}.

\section2 Why is this bad?
The application can't run because it can't import a module it relies on.

\section2 Examples

\qml
import "¯\(ツ)/¯:/path/to/Module"
import QtQuick

Item {
}
\endqml
You can fix this warning by using URLs that have an allowed scheme:
\qml
import "qrc:/path/to/Module"
import QtQuick

Item {
}
\endqml

\note This example assumes that you are not using \l{QQmlAbstractUrlInterceptor}{URL handlers}.

\sa{Import Statements}

*/