Fix Q_DECLARE_METATYPE macro

The macro should stringify value of the given token not the token
itself.

Task-number: QTBUG-37547
Change-Id: I90f4fa613bd13d5a581828ab13f620b40dfd3593
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Jędrzej Nowacki 2014-03-17 09:38:39 +01:00 committed by The Qt Project
parent 8212e0cfad
commit ac178eae4e
2 changed files with 9 additions and 2 deletions

View File

@ -1706,7 +1706,8 @@ inline int qRegisterMetaTypeStreamOperators()
} QT_END_NAMESPACE \
/**/
#define Q_DECLARE_METATYPE(TYPE) \
#define Q_DECLARE_METATYPE(TYPE) Q_DECLARE_METATYPE_IMPL(TYPE)
#define Q_DECLARE_METATYPE_IMPL(TYPE) \
QT_BEGIN_NAMESPACE \
template <> \
struct QMetaTypeId< TYPE > \

View File

@ -278,15 +278,21 @@ void tst_QMetaType::threadSafety()
namespace TestSpace
{
struct Foo { double d; };
struct QungTfu {};
}
Q_DECLARE_METATYPE(TestSpace::Foo)
#define ADD_TESTSPACE(F) TestSpace::F
Q_DECLARE_METATYPE(ADD_TESTSPACE(QungTfu))
void tst_QMetaType::namespaces()
{
TestSpace::Foo nf = { 11.12 };
QVariant v = QVariant::fromValue(nf);
QCOMPARE(qvariant_cast<TestSpace::Foo>(v).d, 11.12);
int qungTfuId = qRegisterMetaType<ADD_TESTSPACE(QungTfu)>();
QCOMPARE(QMetaType::typeName(qungTfuId), "TestSpace::QungTfu");
}
void tst_QMetaType::qMetaTypeId()