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
unresolved-type.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-unresolved-type.html
6\ingroup qmllint-warnings-and-errors
7
8\title Unresolved type
9\brief [unresolved-type] A used type was not found.
10
11\qmllintwarningcategory unresolved-type
12
13This category contains following warnings:
14\list
15\li Type is used but is not resolved
16\li Type was not found for the return type of method
17\li Type was not found for the type of parameter in method
18\li Property has incomplete type; You may be missing an import
19\li Type of property not found; This is likely due to a missing dependency entry or a type not being exposed declaratively
20\li Type of property not fully resolved; This is likely due to a missing dependency entry or a type not being exposed declaratively
21\li Type not found in namespace
22\endlist
23
24These warnings usually indicate missing imports or faulty QML modules, depending
25on whether you are using or writing a QML module.
26
27\section1 For QML module users
28
29\section2 What happened?
30You used a type that was not found by QML tooling.
31It usually indicates a potential typo, a missing \l{qtqml-syntax-imports.html}{import},
32or improperly set up import paths.
33
34\section2 Why is this bad?
35The type can't be found by QML tooling, and most likely not by the QML engine.
36
37\section2 Examples
38\section3 Typo
39\qml
40import QtQuick
41
42Itme { ... }
43\endqml
44To fix this warning, correct the typo:
45\qml
46import QtQuick
47
48Item { ... }
49\endqml
50
51\section3 Missing import statement
52\qml
53
54Item { ... }
55\endqml
56To fix this warning, import the module that exposes \c Item:
57\qml
58import QtQuick
59
60Item { ... }
61\endqml
62
63If adding the import statement does not help, take a look at your
64\l{Import Statements#QML Import Path}{import paths}.
65
66If you get this warning via \QMLLS, your \l{Setting up \QMLLS in Your Editor}{setup} might be
67incomplete.
68
69\section1 For QML module authors
70
71\section2 What happened?
72The QML tooling can't find a type in your QML module. It can be a type that you expose to QML
73directly or indirectly by using it as a:
74\list
75 \li Base type
76 \li Property type
77 \li Signal, slot, or \c Q_INVOKABLE parameter type
78 \li \c Q_INVOKABLE return type
79\endlist
80
81You might be missing a \l{qtqml-cppintegration-definetypes.html}{declarative type registration}
82if the unresolved type is exposed by your module.
83
84Otherwise, your QML module might have undeclared
85\l{qt-add-qml-module.html#declaring-module-dependencies}{dependencies}
86to the QML module exposing the unresolved type.
87
88\section2 Why is this bad?
89The QML tooling will not work on your types and users of your QML module will get
90spurious warnings that they can't fix.
91
92\section2 Examples
93
94\section3 Missing type registration
95
96Refer to \l{Defining QML Types from C++} on how to register your types
97declaratively. Make sure that all types and enums exposed directly and
98indirectly to QML are registered.
99
100\section3 Missing QML module dependency
101
102Let \c MyItem be a C++ type in your QML module:
103\code
104class MyItem: public QQuickItem {
105 ...
106 QML_ELEMENT
107 ...
108 Q_PROPERTY(SomeType someProperty READ someProperty WRITE setSomeProperty NOTIFY somePropertyChanged)
109 ...
110}
111\endcode
112
113The QML tooling can't resolve \c MyItem correctly if it can't resolve \c QQuickItem
114or \c SomeType first. If \c QQuickItem lives in the \c QtQuick QML module and \c SomeType
115in \c SomeModule, then you need to state these C++ dependencies in the QML module definition.
116
117To achieve that, \l{qt-add-qml-module.html#declaring-module-dependencies}{add the dependencies}
118to the QML module definition. This can be done with \c DEPENDENCIES, for example:
119\code
120qt_add_qml_module(
121 ...
122 DEPENDENCIES
123 QtQuick # for QQuickItem to be resolved
124 SomeModule # for SomeType to be resolved
125)
126\endcode
127
128Refer to
129\l{qt-add-qml-module.html#declaring-module-dependencies}{declaring C++ dependencies between QML modules}
130for more information.
131
132*/