summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-06-15 14:14:12 +0200
committerLars Knoll <lars.knoll@qt.io>2020-06-16 13:49:45 +0200
commit30ad4cf558789a0b332d7e038dcfe4f54718e937 (patch)
tree11d872fbff2d98e32f135b08bf0fb6d074740f4b
parent87bc5f7a7ca6240845cc59d877824c7de01d614d (diff)
Warn about constructing QMetaTypes/QVariants with invalid type ids
Warn about using an invalid type id in all cases. So far, only some constructors of QVariant would warn. Move the warning over to the place where we map a typeid to a QMetaTypeInterface to catch all cases. Change-Id: I4cd48a2b5d6c597dbf2afbeae9b811cd0819b768 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/corelib/kernel/qmetatype.cpp2
-rw-r--r--src/corelib/kernel/qvariant.cpp3
2 files changed, 2 insertions, 3 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 262afb2677..10fc5701e5 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -1735,6 +1735,8 @@ static QtPrivate::QMetaTypeInterface *interfaceForType(int typeId)
QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_CONVERT_ID_TO_TYPE)
QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_CONVERT_ID_TO_TYPE)
default:
+ if (typeId != QMetaType::UnknownType)
+ qWarning("Trying to construct an instance of an invalid type, type id: %i", typeId);
return nullptr;
}
}
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 75bdd99dfd..97c1e584ac 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -1752,9 +1752,6 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names
void QVariant::create(int type, const void *copy)
{
d = Private(QMetaType(type));
- if (Q_UNLIKELY(type && !d.type().isValid())) {
- qWarning("Trying to construct an instance of an invalid type, type id: %i", type);
- }
customConstruct(&d, copy);
}