Add nicer error message in qMetaTypeId function.
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>
Tue, 6 Mar 2012 14:12:06 +0000 (15:12 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 7 Mar 2012 11:31:46 +0000 (12:31 +0100)
The function can be used only with a registered type and it would fail
to compile for other types. By adding the static assert we can print
an almost user friendly compilation error message.

Change-Id: I59ab148cabf32afe0baef186b82cb03303b57780
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
src/corelib/kernel/qmetatype.h

index 7f6eaf2..eacb840 100644 (file)
@@ -484,6 +484,7 @@ inline int qMetaTypeId(
 #endif
 )
 {
+    Q_STATIC_ASSERT_X(QMetaTypeId2<T>::Defined, "Type is not registered, please use Q_DECLARE_METATYPE macro to make it know to Qt's meta-object system");
     return QMetaTypeId2<T>::qt_metatype_id();
 }