aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-04-29 13:24:58 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-05-06 10:44:58 +0200
commit22f9e5fb1ed643f284f50b9417bdbafdfb20566b (patch)
tree9c2616522ca98534e2ceb6e4f13a9ffe5c622b93 /src
parent1250d8b5b95eecac767a23563717e53faa5d3b8a (diff)
Add a default message to QML_UNCREATABLE
[ChangeLog][QML][Feature] Add a default message to QML_UNCREATABLE when proving an empty string as a reason Fixes: QTBUG-83842 Change-Id: Ifd2044fa6c56c3a382d451ec47d5f92a1ac16b81 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/doc/src/qmlfunctions.qdoc2
-rw-r--r--src/qml/qml/qqml.cpp11
2 files changed, 10 insertions, 3 deletions
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc
index 9c8cd5e859..f6ed2306c0 100644
--- a/src/qml/doc/src/qmlfunctions.qdoc
+++ b/src/qml/doc/src/qmlfunctions.qdoc
@@ -151,6 +151,8 @@
\l QML_NAMED_ELEMENT(). For such types, \l QML_UNCREATABLE() can be used to
provide a custom error message.
+ Since Qt 6.0 you can use "" instead of a reason to use a standard message instead.
+
\sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_ANONYMOUS
*/
diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp
index 28b48e2eee..a57daf78d2 100644
--- a/src/qml/qml/qqml.cpp
+++ b/src/qml/qml/qqml.cpp
@@ -202,9 +202,14 @@ int QQmlPrivate::qmlregister(RegistrationType type, void *data)
const bool creatable = (elementName != nullptr)
&& boolClassInfo(type.classInfoMetaObject, "QML.Creatable", true);
- const QString noCreateReason = creatable
- ? QString()
- : QString::fromUtf8(classInfo(type.classInfoMetaObject, "QML.UncreatableReason"));
+ QString noCreateReason;
+
+ if (!creatable) {
+ noCreateReason = QString::fromUtf8(classInfo(type.classInfoMetaObject, "QML.UncreatableReason"));
+ if (noCreateReason.isEmpty())
+ noCreateReason = QLatin1String("Type cannot be created in QML.");
+ }
+
RegisterType revisionRegistration = {
0,
type.typeId,