Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
import.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 qmllint-warnings-and-errors-import.html
6\ingroup qmllint-warnings-and-errors
7
8\title Warnings occurred while importing
9\brief [import] The imported module was not found.
10
11\qmllintwarningcategory import
12
13\section1 Failed to import module
14
15\section2 What happened?
16The module imported via \l{Import Statements}{import statement} was not found.
17
18This can be caused, for example, by
19\list
20 \li a typo in the import statement, or
21 \li a user-defined module that was not built, or
22 \li a wrong \l{Import Statements#qml-import-path}{import path}, or
23 \li a missing module
24\endlist
25
26\section2 Why is this bad?
27The application can't run because it can't find a module it relies on.
28
29\section2 Examples
30
31\section3 Typo In The Import Statement
32\qml
33import QtQuicky // not ok: typo in module name
34
35Item {
36}
37\endqml
38To fix this warning, correct the typo:
39\qml
40import QtQuick // ok: no typo in module name
41
42Item {
43}
44\endqml
45
46\section3 User-defined module that was not built
47
48Some tooling like \l{\QMLLS} or \l{qmllint}
49can't find user-defined modules when they
50are not built. If your project defines the QML Module you are trying to import, then
51the QML tooling will not find it until you build it.
52
53\note If building the module does not help when using \l{\QMLLS}, follow the
54instructions in
55\l{Setting up the \QMLLS in Your Editor}{\QMLLS setup instructions}
56and make sure that you communicate the correct build folder to \QMLLS.
57
58\section3 Wrong import path
59
60Please refer to \l{Import Statements#qml-import-path}{the QML import path documentation} and to
61\l{Debugging QML Applications#debugging-module-imports}{the debugging module import documentation}
62for more information about import paths.
63
64\section3 Missing module
65
66If the previous sections did not help to find the imported module, it might be missing.
67This might be caused by a missing dependency. When using external libraries, verify that they are
68actually installed, and that their modules end up in an
69\l{Import Statements#qml-import-path}{import path}.
70
71\section1 Component was not found
72
73\section2 What happened?
74Some component was not found.
75
76\section2 Why is this bad?
77The application can't run because it can't instantiate the non-found component.
78
79\section2 Examples
80
81\section3 Typo in the component name
82\qml
83import QtQuick
84
85Item {
86 Itemy {} // not ok: typo in name
87}
88\endqml
89To fix this warning, correct the typo:
90\qml
91import QtQuick
92
93Item {
94 Item {} // ok: no typo in name
95}
96\endqml
97
98\section3 Missing import statement
99
100\qml
101
102Item { // not ok: must be imported from QtQuick first
103}
104\endqml
105To fix this warning, add the missing module import:
106\qml
107import QtQuick
108
109Item { // ok: was imported from QtQuick
110}
111\endqml
112
113\section1 Import qualifier must start with a capital letter
114
115\section2 What happened?
116Some imported module has an invalid qualifier.
117
118\section2 Why is this bad?
119The module imported with this invalid qualifier can't be used.
120
121\section2 Examples
122
123\qml
124import QtQuick as qq
125
126qq.Item {
127}
128\endqml
129To fix this warning, make the import qualifier start with an upper case letter:
130\qml
131import QtQuick as Qq
132
133Qq.Item {
134}
135\endqml
136
137\section1 Unknown import syntax
138
139\section2 What happened?
140An import statement is using an invalid \l{Import Statements}{import syntax}.
141
142\section2 Why is this bad?
143The application can't run because it can't import a module it relies on.
144
145\section2 Examples
146
147\qml
148import "¯\‍(ツ)/¯:/path/to/Module"
149import QtQuick
150
151Item {
152}
153\endqml
154To fix this warning, use URLs that have an allowed scheme:
155\qml
156import "qrc:/path/to/Module"
157import QtQuick
158
159Item {
160}
161\endqml
162
163\note This example assumes that you are not using \l{QQmlAbstractUrlInterceptor}{URL handlers}.
164
165\sa{Import Statements}
166
167*/