summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp18
-rw-r--r--src/corelib/kernel/qmetaobject_p.h4
-rw-r--r--src/corelib/kernel/qmetaobjectbuilder.cpp14
-rw-r--r--src/corelib/kernel/qmetatype.cpp174
-rw-r--r--src/corelib/kernel/qmetatype.h52
-rw-r--r--src/corelib/kernel/qobject.cpp8
-rw-r--r--src/corelib/kernel/qvariant.cpp37
-rw-r--r--src/corelib/kernel/qvariant.h13
8 files changed, 121 insertions, 199 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index 09297e4c2e..d97373511e 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -171,7 +171,7 @@ static inline const char *rawTypeNameFromTypeInfo(const QMetaObject *mo, uint ty
if (typeInfo & IsUnresolvedType) {
return rawStringData(mo, typeInfo & TypeNameIndexMask);
} else {
- return QMetaType::typeName(typeInfo);
+ return QMetaType(typeInfo).name();
}
}
@@ -180,9 +180,7 @@ static inline QByteArray typeNameFromTypeInfo(const QMetaObject *mo, uint typeIn
if (typeInfo & IsUnresolvedType) {
return stringData(mo, typeInfo & TypeNameIndexMask);
} else {
- // ### Use the QMetaType::typeName() that returns QByteArray
- const char *t = QMetaType::typeName(typeInfo);
- return QByteArray::fromRawData(t, qstrlen(t));
+ return QMetaType(typeInfo).name();
}
}
@@ -190,7 +188,7 @@ static inline int typeFromTypeInfo(const QMetaObject *mo, uint typeInfo)
{
if (!(typeInfo & IsUnresolvedType))
return typeInfo;
- return QMetaType::type(rawStringData(mo, typeInfo & TypeNameIndexMask));
+ return QMetaType::fromName(rawStringData(mo, typeInfo & TypeNameIndexMask)).id();
}
class QMetaMethodPrivate : public QMetaMethod
@@ -1739,7 +1737,7 @@ const char *QMetaMethodPrivate::rawReturnTypeName() const
if (typeInfo & IsUnresolvedType)
return rawStringData(mobj, typeInfo & TypeNameIndexMask);
else
- return QMetaType::typeName(typeInfo);
+ return QMetaType(typeInfo).name();
}
int QMetaMethodPrivate::returnType() const
@@ -2230,7 +2228,7 @@ bool QMetaMethod::invoke(QObject *object,
if (qstrcmp(normalized.constData(), retType) != 0) {
// String comparison failed, try compare the metatype.
int t = returnType();
- if (t == QMetaType::UnknownType || t != QMetaType::type(normalized))
+ if (t == QMetaType::UnknownType || t != QMetaType::fromName(normalized).id())
return false;
}
}
@@ -2316,7 +2314,7 @@ bool QMetaMethod::invoke(QObject *object,
int argIndex = 0;
for (int i = 1; i < paramCount; ++i) {
- types[i] = QMetaType::type(typeNames[i]);
+ types[i] = QMetaType::fromName(typeNames[i]).id();
if (types[i] == QMetaType::UnknownType && param[i]) {
// Try to register the type and try again before reporting an error.
void *argv[] = { &types[i], &argIndex };
@@ -2329,7 +2327,7 @@ bool QMetaMethod::invoke(QObject *object,
}
}
if (types[i] != QMetaType::UnknownType) {
- args[i] = QMetaType::create(types[i], param[i]);
+ args[i] = QMetaType(types[i]).create(param[i]);
++argIndex;
}
}
@@ -2453,7 +2451,7 @@ bool QMetaMethod::invokeOnGadget(void *gadget,
if (qstrcmp(normalized.constData(), retType) != 0) {
// String comparison failed, try compare the metatype.
int t = returnType();
- if (t == QMetaType::UnknownType || t != QMetaType::type(normalized))
+ if (t == QMetaType::UnknownType || t != QMetaType::fromName(normalized).id())
return false;
}
}
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h
index 02ede4d376..0d6cd7396d 100644
--- a/src/corelib/kernel/qmetaobject_p.h
+++ b/src/corelib/kernel/qmetaobject_p.h
@@ -119,7 +119,7 @@ enum EnumFlags {
EnumIsScoped = 0x2
};
-extern int qMetaTypeTypeInternal(const char *);
+Q_CORE_EXPORT int qMetaTypeTypeInternal(const char *);
class QArgumentType
{
@@ -138,7 +138,7 @@ public:
QByteArray name() const
{
if (_type && _name.isEmpty())
- const_cast<QArgumentType *>(this)->_name = QMetaType::typeName(_type);
+ const_cast<QArgumentType *>(this)->_name = QMetaType(_type).name();
return _name;
}
bool operator==(const QArgumentType &other) const
diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp
index 514cfeac55..e451e5cf41 100644
--- a/src/corelib/kernel/qmetaobjectbuilder.cpp
+++ b/src/corelib/kernel/qmetaobjectbuilder.cpp
@@ -81,7 +81,7 @@ QT_BEGIN_NAMESPACE
namespace QtPrivate {
Q_CORE_EXPORT bool isBuiltinType(const QByteArray &type)
{
- int id = QMetaType::type(type);
+ int id = QMetaType::fromName(type).id();
if (!id && !type.isEmpty() && type != "void")
return false;
return (id < QMetaType::User);
@@ -1316,7 +1316,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
const QByteArray &typeName = (i < 0) ? method.returnType : paramTypeNames.at(i);
int typeInfo;
if (QtPrivate::isBuiltinType(typeName))
- typeInfo = QMetaType::type(typeName);
+ typeInfo = QMetaType::fromName(typeName).id();
else
typeInfo = IsUnresolvedType | strings.enter(typeName);
if (buf)
@@ -1343,7 +1343,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
int typeInfo;
if (QtPrivate::isBuiltinType(prop.type))
- typeInfo = QMetaType::type(prop.type);
+ typeInfo = QMetaType::fromName(prop.type).id();
else
typeInfo = IsUnresolvedType | strings.enter(prop.type);
@@ -1438,23 +1438,23 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
if (buf) {
meta->d.metaTypes = types;
for (const auto &prop : d->properties) {
- QMetaType mt(QMetaType::type(prop.type));
+ QMetaType mt = QMetaType::fromName(prop.type);
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
types++;
}
for (const auto &method: d->methods) {
- QMetaType mt(QMetaType::type(method.returnType));
+ QMetaType mt(QMetaType::fromName(method.returnType).id());
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
types++;
for (const auto &parameterType: method.parameterTypes()) {
- QMetaType mt(QMetaType::type(parameterType));
+ QMetaType mt = QMetaType::fromName(parameterType);
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
types++;
}
}
for (const auto &constructor: d->constructors) {
for (const auto &parameterType: constructor.parameterTypes()) {
- QMetaType mt(QMetaType::type(parameterType));
+ QMetaType mt = QMetaType::fromName(parameterType);
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
types++;
}
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 6a8f47f102..595cfd9900 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -539,7 +539,7 @@ int QMetaType::alignOf() const
Returns flags of the type for which this QMetaType instance was constructed.
- \sa QMetaType::TypeFlags, QMetaType::typeFlags()
+ \sa QMetaType::TypeFlags, QMetaType::flags()
*/
QMetaType::TypeFlags QMetaType::flags() const
{
@@ -566,7 +566,7 @@ QMetaType::TypeFlags QMetaType::flags() const
returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or
\nullptr otherwise
- \sa QMetaType::metaObjectForType(), QMetaType::flags()
+ \sa QMetaType::flags()
*/
const QMetaObject *QMetaType::metaObject() const
{
@@ -1620,7 +1620,7 @@ bool QMetaType::registerConverterFunction(const ConverterFunction &f, int from,
{
if (!customTypesConversionRegistry()->insertIfNotContains(qMakePair(from, to), f)) {
qWarning("Type conversion already registered from type %s to type %s",
- QMetaType::typeName(from), QMetaType::typeName(to));
+ QMetaType(from).name(), QMetaType(to).name());
return false;
}
return true;
@@ -2194,107 +2194,16 @@ bool QMetaType::hasRegisteredConverterFunction(int fromTypeId, int toTypeId)
return customTypesConversionRegistry()->contains(qMakePair(fromTypeId, toTypeId));
}
-// We don't officially support constexpr in MSVC 2015, but the limited support it
-// has is enough for the code below.
-
-#define STRINGIFY_TYPE_NAME(MetaTypeName, TypeId, RealName) \
- #RealName "\0"
-#define CALCULATE_TYPE_LEN(MetaTypeName, TypeId, RealName) \
- short(sizeof(#RealName)),
-#define MAP_TYPE_ID_TO_IDX(MetaTypeName, TypeId, RealName) \
- TypeId,
-
-namespace {
-// All type names in one long string.
-constexpr char metaTypeStrings[] = QT_FOR_EACH_STATIC_TYPE(STRINGIFY_TYPE_NAME);
-
-// The sizes of the strings in the metaTypeStrings string (including terminating null)
-constexpr short metaTypeNameSizes[] = {
- QT_FOR_EACH_STATIC_TYPE(CALCULATE_TYPE_LEN)
-};
-
-// The type IDs, in the order of the metaTypeStrings data
-constexpr short metaTypeIds[] = {
- QT_FOR_EACH_STATIC_TYPE(MAP_TYPE_ID_TO_IDX)
-};
-
-constexpr int MetaTypeNameCount = sizeof(metaTypeNameSizes) / sizeof(metaTypeNameSizes[0]);
-
-template <typename IntegerSequence> struct MetaTypeOffsets;
-template <int... TypeIds> struct MetaTypeOffsets<QtPrivate::IndexesList<TypeIds...>>
-{
- // This would have been a lot easier if the meta types that the macro
- // QT_FOR_EACH_STATIC_TYPE declared were in sorted, ascending order, but
- // they're not (i.e., the first one declared is QMetaType::Void == 43,
- // followed by QMetaType::Bool == 1)... As a consequence, we need to use
- // the C++11 constexpr function calculateOffsetForTypeId below in order to
- // create the offset array.
-
- static constexpr int findTypeId(int typeId, int i = 0)
- {
- return i >= MetaTypeNameCount ? -1 :
- metaTypeIds[i] == typeId ? i : findTypeId(typeId, i + 1);
- }
-
- static constexpr short calculateOffsetForIdx(int i)
- {
- return i < 0 ? -1 :
- i == 0 ? 0 : metaTypeNameSizes[i - 1] + calculateOffsetForIdx(i - 1);
- }
-
- static constexpr short calculateOffsetForTypeId(int typeId)
- {
- return calculateOffsetForIdx(findTypeId(typeId));
-#if 0
- // same as, but this is only valid in C++14:
- short offset = 0;
- for (int i = 0; i < MetaTypeNameCount; ++i) {
- if (metaTypeIds[i] == typeId)
- return offset;
- offset += metaTypeNameSizes[i];
- }
- return -1;
-#endif
- }
-
- short offsets[sizeof...(TypeIds)];
- constexpr MetaTypeOffsets() : offsets{calculateOffsetForTypeId(TypeIds)...} {}
-
- const char *operator[](int typeId) const noexcept
- {
- short o = offsets[typeId];
- return o < 0 ? nullptr : metaTypeStrings + o;
- }
-};
-} // anonymous namespace
-
-constexpr MetaTypeOffsets<QtPrivate::Indexes<QMetaType::HighestInternalId + 1>::Value> metaTypeNames {};
-#undef STRINGIFY_TYPE_NAME
-#undef CALCULATE_TYPE_LEN
-#undef MAP_TYPE_ID_TO_IDX
-
/*!
+ \fn const char *QMetaType::typeName(int typeId)
+ \deprecated
+
Returns the type name associated with the given \a typeId, or a null
pointer if no matching type was found. The returned pointer must not be
deleted.
\sa type(), isRegistered(), Type, name()
*/
-const char *QMetaType::typeName(int typeId)
-{
- const uint type = typeId;
- if (Q_LIKELY(type <= QMetaType::HighestInternalId)) {
- return metaTypeNames[typeId];
- } else if (Q_UNLIKELY(type < QMetaType::User)) {
- return nullptr; // It can happen when someone cast int to QVariant::Type, we should not crash...
- }
-
- if (auto reg = customTypeRegistry()) {
- if (auto ti = reg->getCustomType(typeId))
- return ti->name;
- }
- return nullptr;
-}
/*!
\since 5.15
@@ -2305,7 +2214,7 @@ const char *QMetaType::typeName(int typeId)
\sa typeName()
*/
-QByteArray QMetaType::name() const
+const char *QMetaType::name() const
{
return d_ptr ? d_ptr->name : nullptr;
}
@@ -2398,15 +2307,14 @@ static inline int qMetaTypeTypeImpl(const char *typeName, int length)
}
/*!
+ \fn int QMetaType::type(const char *typeName)
+ \deprecated
+
Returns a handle to the type called \a typeName, or QMetaType::UnknownType if there is
no such type.
\sa isRegistered(), typeName(), Type
*/
-int QMetaType::type(const char *typeName)
-{
- return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName, qstrlen(typeName));
-}
/*!
\a internal
@@ -2415,24 +2323,23 @@ int QMetaType::type(const char *typeName)
doesn't attempt to normalize the type name (i.e., the lookup will fail
for type names in non-normalized form).
*/
-int qMetaTypeTypeInternal(const char *typeName)
+Q_CORE_EXPORT int qMetaTypeTypeInternal(const char *typeName)
{
return qMetaTypeTypeImpl</*tryNormalizedType=*/false>(typeName, qstrlen(typeName));
}
/*!
+ \fn int QMetaType::type(const QByteArray &typeName)
+
\since 5.5
\overload
+ \deprecated
Returns a handle to the type called \a typeName, or 0 if there is
no such type.
\sa isRegistered(), typeName()
*/
-int QMetaType::type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
-{
- return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName.constData(), typeName.size());
-}
#ifndef QT_NO_DATASTREAM
/*!
@@ -2522,28 +2429,36 @@ bool QMetaType::load(QDataStream &stream, void *data) const
#endif // QT_NO_DATASTREAM
/*!
+ Returns a QMetaType matching \a typeName. The returned object is
+ not valid if the typeName is not known to QMetaType
+ */
+QMetaType QMetaType::fromName(QByteArrayView typeName)
+{
+ return QMetaType(qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName.data(), typeName.size()));
+}
+
+/*!
+ \fn void *QMetaType::create(int type, const void *copy)
+ \deprecated
+
Returns a copy of \a copy, assuming it is of type \a type. If \a
copy is zero, creates a default constructed instance.
\sa destroy(), isRegistered(), Type
*/
-void *QMetaType::create(int type, const void *copy)
-{
- return QMetaType(type).create(copy);
-}
/*!
+ \fn void QMetaType::destroy(int type, void *data)
+ \deprecated
Destroys the \a data, assuming it is of the \a type given.
\sa create(), isRegistered(), Type
*/
-void QMetaType::destroy(int type, void *data)
-{
- QMetaType(type).destroy(data);
-}
/*!
+ \fn void *QMetaType::construct(int type, void *where, const void *copy)
\since 5.0
+ \deprecated
Constructs a value of the given \a type in the existing memory
addressed by \a where, that is a copy of \a copy, and returns
@@ -2568,14 +2483,12 @@ void QMetaType::destroy(int type, void *data)
\sa destruct(), sizeOf()
*/
-void *QMetaType::construct(int type, void *where, const void *copy)
-{
- return QMetaType(type).construct(where, copy);
-}
/*!
+ \fn void QMetaType::destruct(int type, void *where)
\since 5.0
+ \deprecated
Destructs the value of the given \a type, located at \a where.
@@ -2584,13 +2497,11 @@ void *QMetaType::construct(int type, void *where, const void *copy)
\sa construct()
*/
-void QMetaType::destruct(int type, void *where)
-{
- return QMetaType(type).destruct(where);
-}
/*!
+ \fn int QMetaType::sizeOf(int type)
\since 5.0
+ \deprecated
Returns the size of the given \a type in bytes (i.e. sizeof(T),
where T is the actual type identified by the \a type argument).
@@ -2600,35 +2511,26 @@ void QMetaType::destruct(int type, void *where)
\sa construct(), QMetaType::alignOf()
*/
-int QMetaType::sizeOf(int type)
-{
- return QMetaType(type).sizeOf();
-}
/*!
+ \fn QMetaType::TypeFlags QMetaType::typeFlags(int type)
\since 5.0
+ \deprecated
Returns flags of the given \a type.
\sa QMetaType::TypeFlags
*/
-QMetaType::TypeFlags QMetaType::typeFlags(int type)
-{
- return QMetaType(type).flags();
-}
-
/*!
+ \fn const QMetaObject *QMetaType::metaObjectForType(int type)
\since 5.0
+ \deprecated
returns QMetaType::metaObject for \a type
\sa metaObject()
*/
-const QMetaObject *QMetaType::metaObjectForType(int type)
-{
- return QMetaType(type).metaObject();
-}
/*!
\fn int qRegisterMetaType(const char *typeName)
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index cbf1e19187..ba4f2e8050 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -363,18 +363,39 @@ public:
static void registerNormalizedTypedef(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type);
- static int type(const char *typeName);
-
- static int type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName);
- static const char *typeName(int type);
- static int sizeOf(int type);
- static TypeFlags typeFlags(int type);
- static const QMetaObject *metaObjectForType(int type);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_6_0
+ static int type(const char *typeName)
+ { return QMetaType::fromName(typeName).id(); }
+ QT_DEPRECATED_VERSION_6_0
+ static int type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
+ { return QMetaType::fromName(typeName).id(); }
+ QT_DEPRECATED_VERSION_6_0
+ static const char *typeName(int type)
+ { return QMetaType(type).name(); }
+ QT_DEPRECATED_VERSION_6_0
+ static int sizeOf(int type)
+ { return QMetaType(type).sizeOf(); }
+ QT_DEPRECATED_VERSION_6_0
+ static TypeFlags typeFlags(int type)
+ { return QMetaType(type).flags(); }
+ QT_DEPRECATED_VERSION_6_0
+ static const QMetaObject *metaObjectForType(int type)
+ { return QMetaType(type).metaObject(); }
+ QT_DEPRECATED_VERSION_6_0
+ static void *create(int type, const void *copy = nullptr)
+ { return QMetaType(type).create(copy); }
+ QT_DEPRECATED_VERSION_6_0
+ static void destroy(int type, void *data)
+ { return QMetaType(type).destroy(data); }
+ QT_DEPRECATED_VERSION_6_0
+ static void *construct(int type, void *where, const void *copy)
+ { return QMetaType(type).construct(where, copy); }
+ QT_DEPRECATED_VERSION_6_0
+ static void destruct(int type, void *where)
+ { return QMetaType(type).destruct(where); }
+#endif
static bool isRegistered(int type);
- static void *create(int type, const void *copy = nullptr);
- static void destroy(int type, void *data);
- static void *construct(int type, void *where, const void *copy);
- static void destruct(int type, void *where);
explicit QMetaType(int type);
explicit constexpr QMetaType(QtPrivate::QMetaTypeInterface *d) : d_ptr(d) {}
@@ -387,7 +408,7 @@ public:
int alignOf() const;
TypeFlags flags() const;
const QMetaObject *metaObject() const;
- QT_PREPEND_NAMESPACE(QByteArray) name() const;
+ const char *name() const;
void *create(const void *copy = nullptr) const;
void destroy(void *data) const;
@@ -415,6 +436,7 @@ public:
template<typename T>
static QMetaType fromType();
+ static QMetaType fromName(QByteArrayView name);
friend bool operator==(const QMetaType &a, const QMetaType &b) { return a.id() == b.id(); }
friend bool operator!=(const QMetaType &a, const QMetaType &b) { return !(a == b); }
@@ -1690,7 +1712,7 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (const int id = metatype_id.loadRelaxed()) \
return id; \
- const char *tName = QMetaType::typeName(qMetaTypeId<T>()); \
+ const char *tName = QMetaType::fromType<T>().name(); \
Q_ASSERT(tName); \
const int tNameLen = int(qstrlen(tName)); \
QByteArray typeName; \
@@ -1725,8 +1747,8 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (const int id = metatype_id.loadAcquire()) \
return id; \
- const char *tName = QMetaType::typeName(qMetaTypeId<T>()); \
- const char *uName = QMetaType::typeName(qMetaTypeId<U>()); \
+ const char *tName = QMetaType::fromType<T>().name(); \
+ const char *uName = QMetaType::fromType<U>().name(); \
Q_ASSERT(tName); \
Q_ASSERT(uName); \
const int tNameLen = int(qstrlen(tName)); \
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 4a3356d810..a84d501a32 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -104,7 +104,7 @@ static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
if (typeName.endsWith('*'))
types[i] = QMetaType::VoidStar;
else
- types[i] = QMetaType::type(typeName);
+ types[i] = QMetaType::fromName(typeName).id();
if (!types[i]) {
qWarning("QObject::connect: Cannot queue arguments of type '%s'\n"
@@ -129,7 +129,7 @@ static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc)
else if (type.name().endsWith('*'))
types[i] = QMetaType::VoidStar;
else
- types[i] = QMetaType::type(type.name());
+ types[i] = QMetaType::fromName(type.name()).id();
if (!types[i]) {
qWarning("QObject::connect: Cannot queue arguments of type '%s'\n"
@@ -591,7 +591,7 @@ QMetaCallEvent::~QMetaCallEvent()
int *typeIDs = types();
for (int i = 0; i < d.nargs_; ++i) {
if (typeIDs[i] && d.args_[i])
- QMetaType::destroy(typeIDs[i], d.args_[i]);
+ QMetaType(typeIDs[i]).destroy(d.args_[i]);
}
if (reinterpret_cast<void*>(d.args_) != reinterpret_cast<void*>(prealloc_))
free(d.args_);
@@ -3654,7 +3654,7 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
types[n] = argumentTypes[n-1];
for (int n = 1; n < nargs; ++n)
- args[n] = QMetaType::create(types[n], argv[n]);
+ args[n] = QMetaType(types[n]).create(argv[n]);
}
locker.relock();
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 1e66e249fd..3d39712990 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -1065,8 +1065,7 @@ void QVariant::detach()
*/
const char *QVariant::typeName() const
{
- // Cannot use d.type().name because we must return a char*
- return QMetaType::typeName(d.typeId());
+ return d.type().name();
}
/*!
@@ -1081,29 +1080,26 @@ void QVariant::clear()
}
/*!
+ \fn const char *QVariant::typeToName(int typeId)
+ \deprecated Use QMetaType instead
+
Converts the int representation of the storage type, \a typeId, to
its string representation.
Returns \nullptr if the type is QMetaType::UnknownType or doesn't exist.
*/
-const char *QVariant::typeToName(int typeId)
-{
- return QMetaType::typeName(typeId);
-}
/*!
+ \fn QVariant::Type QVariant::nameToType(const char *name)
+ \deprecated Use QMetaType instead
+
Converts the string representation of the storage type given in \a
name, to its enum representation.
If the string representation cannot be converted to any enum
representation, the variant is set to \c Invalid.
*/
-QVariant::Type QVariant::nameToType(const char *name)
-{
- int metaType = QMetaType::type(name);
- return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType;
-}
#ifndef QT_NO_DATASTREAM
enum { MapFromThreeCount = 36 };
@@ -1190,11 +1186,11 @@ void QVariant::load(QDataStream &s)
s >> is_null;
if (typeId == 27) {
// used to be QRegExp in Qt 4/5
- typeId = QMetaType::type("QRegExp");
+ typeId = QMetaType::fromName("QRegExp").id();
} else if (typeId == QVariant::UserType) {
QByteArray name;
s >> name;
- typeId = QMetaType::type(name.constData());
+ typeId = QMetaType::fromName(name).id();
if (typeId == QMetaType::UnknownType) {
s.setStatus(QDataStream::ReadCorruptData);
qWarning("QVariant::load: unknown user type with name %s.", name.constData());
@@ -1273,7 +1269,7 @@ void QVariant::save(QDataStream &s) const
}
const char *typeName = nullptr;
if (saveAsUserType) {
- typeName = QMetaType::typeName(d.typeId());
+ typeName = d.type().name();
if (!strcmp(typeName, "QRegExp")) {
typeId = 27; // QRegExp in Qt 4/5
typeName = nullptr;
@@ -1283,7 +1279,7 @@ void QVariant::save(QDataStream &s) const
if (s.version() >= QDataStream::Qt_4_2)
s << qint8(d.is_null);
if (typeName)
- s << QMetaType::typeName(userType());
+ s << d.type().name();
if (!isValid()) {
if (s.version() < QDataStream::Qt_5_0)
@@ -1293,7 +1289,7 @@ void QVariant::save(QDataStream &s) const
if (!d.type().save(s, constData())) {
qWarning("QVariant::save: unable to save type '%s' (type id: %d).\n",
- QMetaType::typeName(d.typeId()), d.typeId());
+ d.type().name(), d.typeId());
Q_ASSERT_X(false, "QVariant::save", "Invalid type to save");
}
}
@@ -2001,11 +1997,6 @@ bool QVariant::convert(int targetTypeId)
if (oldValue.d.is_null && oldValue.d.typeId() != QMetaType::Nullptr)
return false;
- if ((QMetaType::typeFlags(oldValue.userType()) & QMetaType::PointerToQObject) && (QMetaType::typeFlags(targetTypeId) & QMetaType::PointerToQObject)) {
- create(targetTypeId, &oldValue.d.get<QObject *>());
- return true;
- }
-
bool ok = QMetaType::convert(oldValue.constData(), oldValue.d.typeId(), data(), targetTypeId);
d.is_null = !ok;
return ok;
@@ -2308,7 +2299,7 @@ QDebug operator<<(QDebug dbg, const QVariant &v)
const uint typeId = v.d.typeId();
dbg.nospace() << "QVariant(";
if (typeId != QMetaType::UnknownType) {
- dbg << QMetaType::typeName(typeId) << ", ";
+ dbg << v.d.type().name() << ", ";
bool streamed = v.d.type().debugStream(dbg, v.d.storage());
if (!streamed && v.canConvert<QString>())
dbg << v.toString();
@@ -2324,7 +2315,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
QDebugStateSaver saver(dbg);
dbg.nospace() << "QVariant::"
<< (int(p) != int(QMetaType::UnknownType)
- ? QMetaType::typeName(p)
+ ? QMetaType(p).name()
: "Invalid");
return dbg;
}
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 41336a2d2d..9ce12ad1b2 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -314,8 +314,17 @@ class Q_CORE_EXPORT QVariant
void load(QDataStream &ds);
void save(QDataStream &ds) const;
#endif
- static const char *typeToName(int typeId);
- static Type nameToType(const char *name);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_6_0
+ static const char *typeToName(int typeId)
+ { return QMetaType(typeId).name(); }
+ QT_DEPRECATED_VERSION_6_0
+ static Type nameToType(const char *name)
+ {
+ int metaType = QMetaType::fromName(name).id();
+ return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType;
+ }
+#endif
void *data();
const void *constData() const