diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index d4ea231a7ed..740dcbc9bef 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -36,6 +36,7 @@ #include #include +#include Q_DECLARE_METATYPE(QMetaType::Type) @@ -237,6 +238,12 @@ struct GenericPODType : BaseGenericType QByteArray podData; }; +// The order of the next two statics matters! +// +// need to use shared_ptr, for its template ctor, since QMetaTypeInterface isn't polymorphic, +// but the test derives from it +static std::vector> s_metaTypeInterfaces; + using RegisteredType = QPair, std::shared_ptr>; static QHash s_managedTypes; @@ -326,7 +333,7 @@ void tst_QMetaType::registerGadget(const char *name, const QList const QMetaObject * { @@ -345,7 +352,7 @@ void tst_QMetaType::registerGadget(const char *name, const QListm_metatype = gadgetMetaType; int gadgetTypeId = QMetaType(typeInfo).id(); @@ -1241,7 +1248,7 @@ void tst_QMetaType::typedConstruct() dynamicGadgetProperties->podData = myPodTesData; const auto flags = QMetaType::NeedsConstruction | QMetaType::NeedsDestruction; using TypeInfo = QtPrivate::QMetaTypeInterface; - auto typeInfo = new TypeInfo { + auto typeInfo = s_metaTypeInterfaces.emplace_back(new TypeInfo { 0, alignof(GenericGadgetType), sizeof(GenericGadgetType), uint(flags), 0, nullptr, podTypeName, [](const TypeInfo *self, void *where) { GadgetTypedConstructor(self->typeId, where, nullptr); }, [](const TypeInfo *self, void *where, const void *copy) { GadgetTypedConstructor(self->typeId, where, copy); }, @@ -1253,7 +1260,7 @@ void tst_QMetaType::typedConstruct() GadgetSaveOperator, GadgetLoadOperator, nullptr - }; + }).get(); QMetaType metatype(typeInfo); dynamicGadgetProperties->m_metatype = metatype; int podTypeId = metatype.id();