QMetaType: Do not warn about unknown types in isRegistered

isRegistered naturally has the potential to run into unregistered
types; in that case, we should not print any warning.

Pick-to: 6.4 6.3 6.2
Change-Id: I060b23199ed1d41f67ebe656ed3c396094edffd4
Reviewed-by: Stefan Gehn <stefan.gehn@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Fabian Kosmale 2022-06-29 09:00:28 +02:00
parent 4851eae5ba
commit e19bd973e3

View File

@ -2593,6 +2593,20 @@ void QMetaType::registerNormalizedTypedef(const NS(QByteArray) & normalizedTypeN
}
}
static const QtPrivate::QMetaTypeInterface *interfaceForTypeNoWarning(int typeId)
{
const QtPrivate::QMetaTypeInterface *iface = nullptr;
if (typeId >= QMetaType::User) {
if (customTypeRegistry.exists())
iface = customTypeRegistry->getCustomType(typeId);
} else {
if (auto moduleHelper = qModuleHelperForType(typeId))
iface = moduleHelper->interfaceForType(typeId);
}
return iface;
}
/*!
Returns \c true if the datatype with ID \a type is registered;
otherwise returns \c false.
@ -2601,7 +2615,7 @@ void QMetaType::registerNormalizedTypedef(const NS(QByteArray) & normalizedTypeN
*/
bool QMetaType::isRegistered(int type)
{
return QMetaType(type).isRegistered();
return interfaceForTypeNoWarning(type) != nullptr;
}
template <bool tryNormalizedType>
@ -2959,15 +2973,7 @@ QMetaType QMetaType::fromName(QByteArrayView typeName)
static const QtPrivate::QMetaTypeInterface *interfaceForType(int typeId)
{
const QtPrivate::QMetaTypeInterface *iface = nullptr;
if (typeId >= QMetaType::User) {
if (customTypeRegistry.exists())
iface = customTypeRegistry->getCustomType(typeId);
} else {
if (auto moduleHelper = qModuleHelperForType(typeId))
iface = moduleHelper->interfaceForType(typeId);
}
const QtPrivate::QMetaTypeInterface *iface = interfaceForTypeNoWarning(typeId);
if (!iface && typeId != QMetaType::UnknownType)
qWarning("Trying to construct an instance of an invalid type, type id: %i", typeId);