Remove QMetaType::unregisterType().
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>
Fri, 3 Feb 2012 11:54:25 +0000 (12:54 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 7 Feb 2012 07:53:18 +0000 (08:53 +0100)
The function hasn't been working properly. It was not well tested, for
example it is undefined how QVariant should behave if it contains an
instance of an unregistered type.

Concept of unregistering types was inspired by plug-in system, but in
most supported platforms we do not unload plug-ins.

Idea of type unregistering may block optimizations in meta object
system, because it would be not possible to cache a type id.
QMetaType::type() could return different ids for the same name.

Currently QMetaType::unregisterType() is not used in Qt.

Change-Id: I878b6e8d91de99f9bcefeab73af2e2ba0bd0cba0
Reviewed-by: Prasanth Ullattil <prasanth.ullattil@nokia.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
dist/changes-5.0.0
src/corelib/kernel/qmetatype.cpp
src/corelib/kernel/qmetatype.h
tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp

index 280b5d9..617b2d3 100644 (file)
@@ -45,7 +45,9 @@ information about a particular change.
   in Qt4, so these methods return a bool now. If your code used the undocumented
   QBool, simply replace it with bool.
 
-- QMetaType::construct() has been renamed to QMetaType::create().
+- QMetaType:
+  * QMetaType::construct() has been renamed to QMetaType::create().
+  * QMetaType::unregisterType() has been removed.
 
 - QTestLib:
   * The QTRY_VERIFY and QTRY_COMPARE macros have been moved into QTestLib.
index 50b11e0..b31bece 100644 (file)
@@ -532,36 +532,6 @@ int QMetaType::registerTypedef(const char* typeName, int aliasId)
 }
 
 /*!
-    \since 4.4
-
-    Unregisters a user type, with \a typeName.
-
-    \sa type(), typeName()
- */
-void QMetaType::unregisterType(const char *typeName)
-{
-    QVector<QCustomTypeInfo> *ct = customTypes();
-    if (!ct || !typeName)
-        return;
-
-#ifdef QT_NO_QOBJECT
-    NS(QByteArray) normalizedTypeName = typeName;
-#else
-    NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
-#endif
-    QWriteLocker locker(customTypesLock());
-    for (int v = 0; v < ct->count(); ++v) {
-        if (ct->at(v).typeName == typeName) {
-            QCustomTypeInfo &inf = (*ct)[v];
-            inf.typeName.clear();
-            inf.creator = 0;
-            inf.deleter = 0;
-            inf.alias = -1;
-        }
-    }
-}
-
-/*!
     Returns true if the datatype with ID \a type is registered;
     otherwise returns false.
 
index 0ea9d26..e99c93c 100644 (file)
@@ -247,7 +247,6 @@ public:
     static void destroy(int type, void *data);
     static void *construct(int type, void *where, const void *copy);
     static void destruct(int type, void *where);
-    static void unregisterType(const char *typeName);
 
 #ifndef QT_NO_DATASTREAM
     static bool save(QDataStream &stream, int type, const void *data);
index be13b39..ca2964d 100644 (file)
@@ -87,7 +87,6 @@ private slots:
     void typedefs();
     void isRegistered_data();
     void isRegistered();
-    void unregisterType();
     void registerStreamBuiltin();
     void automaticTemplateRegistration();
 };
@@ -857,28 +856,6 @@ void tst_QMetaType::isRegistered()
     QCOMPARE(QMetaType::isRegistered(typeId), registered);
 }
 
-class RegUnreg
-{
-public:
-    RegUnreg() {};
-    RegUnreg(const RegUnreg &) {};
-    ~RegUnreg() {};
-};
-
-void tst_QMetaType::unregisterType()
-{
-    // cannot unregister standard types
-    int typeId = qRegisterMetaType<QList<QVariant> >("QList<QVariant>");
-    QCOMPARE(QMetaType::isRegistered(typeId), true);
-    QMetaType::unregisterType("QList<QVariant>");
-    QCOMPARE(QMetaType::isRegistered(typeId), true);
-    // allow unregister user types
-    typeId = qRegisterMetaType<RegUnreg>("RegUnreg");
-    QCOMPARE(QMetaType::isRegistered(typeId), true);
-    QMetaType::unregisterType("RegUnreg");
-    QCOMPARE(QMetaType::isRegistered(typeId), false);
-}
-
 void tst_QMetaType::registerStreamBuiltin()
 {
     //should not crash;