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
67\l{qtqml-tooling-qmlls.html#setting-up-the-qml-language-server-in-your-editor}{setup}
68might be incomplete.
69
70\section1 For QML module authors
71
72\section2 What happened?
73The QML tooling can't find a type in your QML module. It can be a type that you expose to QML
74directly or indirectly by using it as a:
75\list
76 \li Base type
77 \li Property type
78 \li Signal, slot, or \c Q_INVOKABLE parameter type
79 \li \c Q_INVOKABLE return type
80\endlist
81
82You might be missing a \l{qtqml-cppintegration-definetypes.html}{declarative type registration}
83if the unresolved type is exposed by your module.
84
85Otherwise, your QML module might have undeclared
86\l{qt-add-qml-module.html#declaring-module-dependencies}{dependencies}
87to the QML module exposing the unresolved type.
88
89\section2 Why is this bad?
90The QML tooling will not work on your types and users of your QML module will get
91spurious warnings that they can't fix.
92
93\section2 Examples
94
95\section3 Missing type registration
96
97Refer to \l{Defining QML Types from C++} on how to register your types
98declaratively. Make sure that all types and enums exposed directly and
99indirectly to QML are registered.
100
101\section3 Missing QML module dependency
102
103Let \c MyItem be a C++ type in your QML module:
104\code
105class MyItem: public QQuickItem {
106 ...
107 QML_ELEMENT
108 ...
109 Q_PROPERTY(SomeType someProperty READ someProperty WRITE setSomeProperty NOTIFY somePropertyChanged)
110 ...
111}
112\endcode
113
114The QML tooling can't resolve \c MyItem correctly if it can't resolve \c QQuickItem
115or \c SomeType first. If \c QQuickItem lives in the \c QtQuick QML module and \c SomeType
116in \c SomeModule, then you need to state these C++ dependencies in the QML module definition.
117
118To achieve that, \l{qt-add-qml-module.html#declaring-module-dependencies}{add the dependencies}
119to the QML module definition. This can be done with \c DEPENDENCIES, for example:
120\code
121qt_add_qml_module(
122 ...
123 DEPENDENCIES
124 QtQuick # for QQuickItem to be resolved
125 SomeModule # for SomeType to be resolved
126)
127\endcode
128
129Refer to
130\l{qt-add-qml-module.html#declaring-module-dependencies}{declaring C++ dependencies between QML modules}
131for more information.
132
133*/