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