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