aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-08-01 14:25:49 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-08-29 14:51:27 +0200
commit0f4f59a1f73cb22359cec86297ea4131d209369d (patch)
tree2a0345d2fb007f250f59c5dd656de1929f2e7793 /src
parent8b6199c70817dd75a254055fd7e35e5acb54bf9c (diff)
QmlCompiler: Add more informative warning for unknown object types
The most common mistakes leading there are missing qualifications in C++ and missing qt_extract_metatypes in CMake. Fixes: QTBUG-105254 Change-Id: I285355d0cc5be34d5e018dc6e843e649f60df871 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 87e9ea9efa3baeecea91e32964166fc794ff5161)
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljstyperesolver.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp
index 046a79ce01..6a0839e9e0 100644
--- a/src/qmlcompiler/qqmljstyperesolver.cpp
+++ b/src/qmlcompiler/qqmljstyperesolver.cpp
@@ -643,7 +643,8 @@ QQmlJSScope::ConstPtr QQmlJSTypeResolver::genericType(const QQmlJSScope::ConstPt
return m_metaObjectType;
if (type->accessSemantics() == QQmlJSScope::AccessSemantics::Reference) {
- for (auto base = type; base; base = base->baseType()) {
+ QString unresolvedBaseTypeName;
+ for (auto base = type; base;) {
// QObject and QQmlComponent are the two required base types.
// Any QML type system has to define those, or use the ones from builtins.
// As QQmlComponent is derived from QObject, we can restrict ourselves to the latter.
@@ -655,10 +656,19 @@ QQmlJSScope::ConstPtr QQmlJSTypeResolver::genericType(const QQmlJSScope::ConstPt
&& base->internalName() == u"QQmlComponent"_s) {
return base;
}
+
+ if (auto baseBase = base->baseType()) {
+ base = baseBase;
+ } else {
+ unresolvedBaseTypeName = base->baseTypeName();
+ break;
+ }
}
- m_logger->log(u"Object type %1 is not derived from QObject or QQmlComponent"_s.arg(
- type->internalName()),
+ m_logger->log(u"Object type %1 is not derived from QObject or QQmlComponent. "
+ "You may need to fully qualify all names in C++ so that moc can see them. "
+ "You may also need to add qt_extract_metatypes(<target containing %2>)."_s
+ .arg(type->internalName(), unresolvedBaseTypeName),
Log_Compiler, type->sourceLocation());
// Reference types that are not QObject or QQmlComponent are likely JavaScript objects.