This category contains following warnings:
These warnings usually indicate missing imports or faulty QML modules, depending on whether you are using or writing a QML module.
This warning category is spelled
[unresolved-type]
by qmllint.
You used a type that was not found by QML tooling. It usually indicates a potential typo, a missing import , or improperly set up import paths.
The type can't be found by QML tooling, and most likely not by the QML engine.
import QtQuick
Itme { ... }
To fix this warning, correct the typo:
import QtQuick
Item { ... }
Item { ... }
To fix this warning, import the module that exposes
Item
:
import QtQuick
Item { ... }
If adding the import statement does not help, take a look at your import paths .
If you get this warning via QML Language Server, your setup might be incomplete.
The QML tooling can't find a type in your QML module. It can be a type that you expose to QML directly or indirectly by using it as a:
Q_INVOKABLE
parameter type
Q_INVOKABLE
return type
You might be missing a declarative type registration if the unresolved type is exposed by your module.
Otherwise, your QML module might have undeclared dependencies to the QML module exposing the unresolved type.
The QML tooling will not work on your types and users of your QML module will get spurious warnings that they can't fix.
参考 从 C++ 定义 QML 类型 on how to register your types declaratively. Make sure that all types and enums exposed directly and indirectly to QML are registered.
Let
MyItem
be a C++ type in your QML module:
class MyItem: public QQuickItem { ... QML_ELEMENT ... Q_PROPERTY(SomeType someProperty READ someProperty WRITE setSomeProperty NOTIFY somePropertyChanged) ... }
The QML tooling can't resolve
MyItem
correctly if it can't resolve
QQuickItem
or
SomeType
first. If
QQuickItem
lives in the
QtQuick
QML module and
SomeType
in
SomeModule
, then you need to state these C++ dependencies in the QML module definition.
To achieve that,
add the dependencies
to the QML module definition. This can be done with
DEPENDENCIES
,例如:
qt_add_qml_module(
...
DEPENDENCIES
QtQuick # for QQuickItem to be resolved
SomeModule # for SomeType to be resolved
)