From 30ad4cf558789a0b332d7e038dcfe4f54718e937 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 15 Jun 2020 14:14:12 +0200 Subject: [PATCH] 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 Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetatype.cpp | 2 ++ src/corelib/kernel/qvariant.cpp | 3 --- 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); }