int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
normalizedTypeName.size());
+ int previousSize = 0;
+ int previousFlags = 0;
if (!idx) {
QWriteLocker locker(customTypesLock());
idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
inf.flags = flags;
idx = ct->size() + User;
ct->append(inf);
+ return idx;
}
+
+ if (idx >= User) {
+ previousSize = ct->at(idx - User).size;
+ previousFlags = ct->at(idx - User).flags;
+ }
+ }
+
+ if (idx < User) {
+ previousSize = QMetaType::sizeOf(idx);
+ previousFlags = QMetaType::typeFlags(idx);
+ }
+
+ if (previousSize != size) {
+ qFatal("QMetaType::registerType: Binary compatibility break "
+ "-- Size mismatch for type '%s' [%i]. Previously registered "
+ "size %i, now registering size %i.",
+ normalizedTypeName.constData(), idx, previousSize, size);
}
+ if (previousFlags != flags) {
+ qFatal("QMetaType::registerType: Binary compatibility break "
+ "-- Type flags for type '%s' [%i] don't match. Previously "
+ "registered TypeFlags(0x%x), now registering TypeFlags(0x%x).",
+ normalizedTypeName.constData(), idx, previousFlags, int(flags));
+ }
+
return idx;
}
int idx = qMetaTypeStaticType(normalizedTypeName.constData(),
normalizedTypeName.size());
- if (idx) {
- Q_ASSERT(idx == aliasId);
- return idx;
- }
-
- QWriteLocker locker(customTypesLock());
- idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
- normalizedTypeName.size());
+ if (!idx) {
+ QWriteLocker locker(customTypesLock());
+ idx = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
+ normalizedTypeName.size());
- if (idx)
- return idx;
+ if (!idx) {
+ QCustomTypeInfo inf;
+ inf.typeName = normalizedTypeName;
+ inf.alias = aliasId;
+ inf.creator = 0;
+ inf.deleter = 0;
+ ct->append(inf);
+ return aliasId;
+ }
+ }
- QCustomTypeInfo inf;
- inf.typeName = normalizedTypeName;
- inf.alias = aliasId;
- inf.creator = 0;
- inf.deleter = 0;
- ct->append(inf);
- return aliasId;
+ if (idx != aliasId) {
+ qFatal("QMetaType::registerTypedef: Binary compatibility break "
+ "-- Type name '%s' previously registered as typedef of '%s' [%i], "
+ "now registering as typedef of '%s' [%i].",
+ normalizedTypeName.constData(), QMetaType::typeName(idx), idx,
+ QMetaType::typeName(aliasId), aliasId);
+ }
+ return idx;
}
/*!
void constructCopy_data();
void constructCopy();
void typedefs();
+ void registerType();
void isRegistered_data();
void isRegistered();
void registerStreamBuiltin();
QCOMPARE(QMetaType::type("WhityDouble"), ::qMetaTypeId<WhityDouble>());
}
+void tst_QMetaType::registerType()
+{
+ // Built-in
+ QCOMPARE(qRegisterMetaType<QString>("QString"), int(QMetaType::QString));
+ QCOMPARE(qRegisterMetaType<QString>("QString"), int(QMetaType::QString));
+
+ // Custom
+ int fooId = qRegisterMetaType<TestSpace::Foo>("TestSpace::Foo");
+ QVERIFY(fooId >= int(QMetaType::User));
+ QCOMPARE(qRegisterMetaType<TestSpace::Foo>("TestSpace::Foo"), fooId);
+
+ int movableId = qRegisterMetaType<CustomMovable>("CustomMovable");
+ QVERIFY(movableId >= int(QMetaType::User));
+ QCOMPARE(qRegisterMetaType<CustomMovable>("CustomMovable"), movableId);
+
+ // Alias to built-in
+ typedef QString MyString;
+
+ QCOMPARE(qRegisterMetaType<MyString>("MyString"), int(QMetaType::QString));
+ QCOMPARE(qRegisterMetaType<MyString>("MyString"), int(QMetaType::QString));
+
+ QCOMPARE(QMetaType::type("MyString"), int(QMetaType::QString));
+
+ // Alias to custom type
+ typedef CustomMovable MyMovable;
+ typedef TestSpace::Foo MyFoo;
+
+ QCOMPARE(qRegisterMetaType<MyMovable>("MyMovable"), movableId);
+ QCOMPARE(qRegisterMetaType<MyMovable>("MyMovable"), movableId);
+
+ QCOMPARE(QMetaType::type("MyMovable"), movableId);
+
+ QCOMPARE(qRegisterMetaType<MyFoo>("MyFoo"), fooId);
+ QCOMPARE(qRegisterMetaType<MyFoo>("MyFoo"), fooId);
+
+ QCOMPARE(QMetaType::type("MyFoo"), fooId);
+}
+
class IsRegisteredDummyType { };
void tst_QMetaType::isRegistered_data()