1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5\page qmllint-warnings-and-errors-missing-type.html
6\ingroup qmllint-warnings-and-errors
9\brief A type used in a binding or alias was not found.
11This warning category has multiple warnings:
13 \li \l{Cannot Deduce Type of Alias}
14 \li \l{No Type Found For Property}
17\section1 Cannot Deduce Type of Alias
19\section2 What happened?
20An alias property points to a property with a C++ type whose QML counterpart was not found. This can
21be caused by importing a QML module which do not declare its QML dependencies on other modules.
23\note If you are importing QML modules with external dependencies, verify that they are
24actually installed, and that their modules end up in an
25\l{Import Statements#qml-import-path}{import path}.
27The warning might also indicate that the type of the property referenced by the alias does not have
28a QML counterpart. The referenced property type might be missing the
29\l{QQmlEngine::}{QML_ELEMENT} macro, for example. Refer to
30\l{Defining QML Types from C++} or \l{Overview - QML and C++ Integration} in this case.
32\section2 Why is this bad?
33QML tooling is not able to find the QML counterpart of the C++ type: the
34\l{Qt Quick Compiler}{compiler} can't compile this property alias to
35C++ and \l{qmllint Reference}{qmllint} as well as \l{\QMLLS Reference}{\QMLLS}
36can't analyze this property alias.
39Let our QML module have one C++ class with a property \c{myProperty}:
43#include <QtQml/qqmlregistration.h>
46class MyCppObject : public QObject
51 MyCppObject(QObject *parent = nullptr)
55 Q_PROPERTY(QQuickItem *myProperty READ myProperty WRITE setMyProperty NOTIFY notifyMyProperty)
56 QQuickItem *myProperty() { return m_myProperty; }
57 void setMyProperty(QQuickItem *item) { emit notifyMyProperty(); m_myProperty = item; }
60 QQuickItem *m_myProperty;
63 void notifyMyProperty();
67with following \c{CMakeLists.txt}:
69project(mymodule VERSION 0.1 LANGUAGES CXX)
71set(CMAKE_CXX_STANDARD_REQUIRED ON)
72find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
73qt_standard_project_setup(REQUIRES 6.5)
75qt_add_executable(appmymodule
79qt_add_qml_module(appmymodule
82 QML_FILES Main.qml HelloWorld.qml
83 SOURCES mycppobject.cpp mycppobject.h
86target_link_libraries(appmymodule
91The C++ dependency \c{Quick} was declared, such that this class can compile and the QQuickItem
92include can be found. Also, \c{mymodule} does not have any dependency on QtQuick.
94Now, let's try to use \c{myProperty} in an alias in QML. The program will run but QML tooling like
95the \l{Qt Quick Compiler}{compiler}, for example, will complain about the usage of \c{myProperty}:
102 property alias myAlias: root.myProperty // not ok: Cannot deduce type of alias [missing-type]
105The reason for the warning message is that in the QML code, the type \c{QQuickItem} of
106\c{myProperty} and its QML counterpart \c{Item} are not known, even if you have \c{import QtQuick}
107in your QML file. This is because the same type can be exposed multiple times with different
108attributes in different modules: \c{mymodule} actually has to be precise about the QML type of
111You can fix this warning by adding the dependency in the \c{CMakeLists.txt}:
113qt_add_qml_module(mymodule
116 # declarare QML dependency to QtQuick module
122Now, the warning should be gone!
124\b {See also} \l {Declaring module dependencies}.
126\section1 No Type Found For Property
128\section2 What happened?
129A binding was set on a property whose QML type was not found. This can be caused by a QML module
130which does not declare its QML dependencies on other modules.
132\note If you are importing QML modules with external dependencies, verify that they are
133actually installed, and that their modules end up in an
134\l{Import Statements#qml-import-path}{import path}.
136The warning might also indicate that the type of the property does not have
137a QML counterpart. The property type might be missing the
138\l{QQmlEngine::}{QML_ELEMENT} macro, for example. Refer to
139\l{Defining QML Types from C++} or \l{Overview - QML and C++ Integration} in this case.
141\section2 Why is this bad?
142QML tooling is not able to find the QML counterpart of the C++ type: the
143\l{Qt Quick Compiler}{compiler} can't compile this property binding to
144C++ and \l{qmllint Reference}{qmllint} as well as \l{\QMLLS Reference}{\QMLLS} can't analyze this property binding.
147Let our QML module have a C++ class with two properties, \c{myProperty} and \c{myProperty2}:
151#include <QtQml/qqmlregistration.h>
154class MyCppObject : public QObject
159 MyCppObject(QObject *parent = nullptr)
163 Q_PROPERTY(QQuickItem *myProperty READ myProperty WRITE setMyProperty NOTIFY notifyMyProperty)
164 QQuickItem *myProperty() { return m_myProperty; }
165 void setMyProperty(QQuickItem *item) { emit notifyMyProperty(); m_myProperty = item; }
167 Q_PROPERTY(QQuickItem *myProperty2 READ myProperty2 WRITE setMyProperty2 NOTIFY notifyMyProperty2)
168 QQuickItem *myProperty2() { return m_myProperty2; }
169 void setMyProperty2(QQuickItem *item) { emit notifyMyProperty2(); m_myProperty2 = item; }
172 QQuickItem *m_myProperty;
173 QQuickItem *m_myProperty2;
176 void notifyMyProperty();
177 void notifyMyProperty2();
181with following \c{CMakeLists.txt}:
183project(mymodule VERSION 0.1 LANGUAGES CXX)
185set(CMAKE_CXX_STANDARD_REQUIRED ON)
186find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
187qt_standard_project_setup(REQUIRES 6.5)
189qt_add_executable(appmymodule
193qt_add_qml_module(appmymodule
196 QML_FILES Main.qml HelloWorld.qml
197 SOURCES mycppobject.cpp mycppobject.h
200target_link_libraries(appmymodule
205The C++ dependency \c{Quick} was declared, such that this class can compile and the QQuickItem
206include can be found. Also, \c{mymodule} does not have any dependency on QtQuick.
208Now, let's try to bind \c{myProperty2} to \c{myProperty} in an alias in QML. The program will run
209but QML tooling like the \l{Qt Quick Compiler}{compiler}, for example, will complain about the
210usage of \c{myProperty}:
218 myProperty: myProperty2 // not ok: No type found for property "myProperty". [missing-type]
221The reason for the warning message is that in the QML code, the type \c{QQuickItem} of \c{myProperty}
222and its QML counterpart \c{Item} are not known: the dependency 'QtQuick' of mymodule was not
223declared in the \c{CMakeLists.txt}.
225You can fix this warning by adding the dependency in the \c{CMakeLists.txt}:
227qt_add_qml_module(mymodule
230 # declarare QML dependency to QtQuick module
236Now, the warning should be gone!
238\b {See also} \l {Declaring module dependencies}.