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