From 0d09c6bfa5da53fedc794d6dc99f5675bdf59d49 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 30 Nov 2009 12:06:57 +0100 Subject: Do not recoginze templated types or pointers as flags. Those types can never by flags. This fixes QML as they do not use Q_DECLARE_METATYPE in a way visible to moc. Patch by Aaron Kennedy Reviewed-by: Kent Hansen --- src/tools/moc/generator.cpp | 3 ++- tests/auto/moc/namespaced-flags.h | 5 +++++ tests/auto/moc/tst_moc.cpp | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 1ed6586..8fcc0df 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -292,7 +292,8 @@ void Generator::generateCode() QList extraList; for (int i = 0; i < cdef->propertyList.count(); ++i) { const PropertyDef &p = cdef->propertyList.at(i); - if (!isVariantType(p.type) && !metaTypes.contains(p.type)) { + if (!isVariantType(p.type) && !metaTypes.contains(p.type) && !p.type.contains('*') && + !p.type.contains('<') && !p.type.contains('>')) { int s = p.type.lastIndexOf("::"); if (s > 0) { QByteArray scope = p.type.left(s); diff --git a/tests/auto/moc/namespaced-flags.h b/tests/auto/moc/namespaced-flags.h index d3f9548..b366447 100644 --- a/tests/auto/moc/namespaced-flags.h +++ b/tests/auto/moc/namespaced-flags.h @@ -62,13 +62,18 @@ namespace Foo { Q_OBJECT //Q_PROPERTY( Bar::Flags flags READ flags WRITE setFlags ) // triggers assertion Q_PROPERTY( Foo::Bar::Flags flags READ flags WRITE setFlags ) // fails to compile, or with the same assertion if moc fix is applied + Q_PROPERTY( QList flagsList READ flagsList WRITE setFlagsList ) public: explicit Baz( QObject * parent=0 ) : QObject( parent ), mFlags() {} void setFlags( Bar::Flags f ) { mFlags = f; } Bar::Flags flags() const { return mFlags; } + + void setFlagsList( const QList &f ) { mList = f; } + QList flagsList() const { return mList; } private: Bar::Flags mFlags; + QList mList; }; } diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp index 69d6ca7..2316ba2 100644 --- a/tests/auto/moc/tst_moc.cpp +++ b/tests/auto/moc/tst_moc.cpp @@ -489,7 +489,6 @@ private slots: void constructors(); void typenameWithUnsigned(); void warnOnVirtualSignal(); - signals: void sigWithUnsignedArg(unsigned foo); void sigWithSignedArg(signed foo); @@ -817,6 +816,8 @@ void tst_Moc::structQObject() #include "namespaced-flags.h" +Q_DECLARE_METATYPE(QList); + void tst_Moc::namespacedFlags() { Foo::Baz baz; @@ -829,6 +830,12 @@ void tst_Moc::namespacedFlags() QVERIFY(v.isValid()); QVERIFY(baz.setProperty("flags", v)); QVERIFY(baz.flags() == bar.flags()); + + QList l; + l << baz.flags(); + QVariant v2 = baz.setProperty("flagsList", QVariant::fromValue(l)); + QCOMPARE(l, baz.flagsList()); + QCOMPARE(l, qvariant_cast >(baz.property("flagsList"))); } void tst_Moc::warnOnMultipleInheritance() -- cgit v0.12