diff options
Diffstat (limited to 'examples/qml/referenceexamples/attached')
-rw-r--r-- | examples/qml/referenceexamples/attached/birthdayparty.h | 10 | ||||
-rw-r--r-- | examples/qml/referenceexamples/attached/main.cpp | 9 | ||||
-rw-r--r-- | examples/qml/referenceexamples/attached/person.h | 5 |
3 files changed, 15 insertions, 9 deletions
diff --git a/examples/qml/referenceexamples/attached/birthdayparty.h b/examples/qml/referenceexamples/attached/birthdayparty.h index 15375f14d9..308d0652a8 100644 --- a/examples/qml/referenceexamples/attached/birthdayparty.h +++ b/examples/qml/referenceexamples/attached/birthdayparty.h @@ -59,6 +59,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) + QML_ANONYMOUS public: BirthdayPartyAttached(QObject *object); @@ -75,6 +76,12 @@ class BirthdayParty : public QObject Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT + +//! [declare attached] + QML_ATTACHED(BirthdayPartyAttached) +//! [declare attached] + public: BirthdayParty(QObject *parent = nullptr); @@ -93,7 +100,4 @@ private: QList<Person *> m_guests; }; -//! [declare attached] -QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) -//! [declare attached] #endif // BIRTHDAYPARTY_H diff --git a/examples/qml/referenceexamples/attached/main.cpp b/examples/qml/referenceexamples/attached/main.cpp index eb70625bea..ab1c6b9637 100644 --- a/examples/qml/referenceexamples/attached/main.cpp +++ b/examples/qml/referenceexamples/attached/main.cpp @@ -58,12 +58,9 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterAnonymousType<BirthdayPartyAttached>("People", 1); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterAnonymousType<ShoeDescription>("People", 1); - qmlRegisterAnonymousType<Person>("People", 1); - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); + qmlRegisterTypesAndRevisions<BirthdayPartyAttached, + BirthdayParty, ShoeDescription, + Person, Boy, Girl>("People", 1); QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); diff --git a/examples/qml/referenceexamples/attached/person.h b/examples/qml/referenceexamples/attached/person.h index 2398da38bf..239f4405c0 100644 --- a/examples/qml/referenceexamples/attached/person.h +++ b/examples/qml/referenceexamples/attached/person.h @@ -52,6 +52,7 @@ #include <QObject> #include <QColor> +#include <QtQml/qqml.h> class ShoeDescription : public QObject { @@ -60,6 +61,7 @@ class ShoeDescription : public QObject Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QString brand READ brand WRITE setBrand) Q_PROPERTY(qreal price READ price WRITE setPrice) + QML_ANONYMOUS public: ShoeDescription(QObject *parent = 0); @@ -86,6 +88,7 @@ class Person : public QObject Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(ShoeDescription *shoe READ shoe) + QML_ANONYMOUS public: Person(QObject *parent = nullptr); @@ -101,6 +104,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -108,6 +112,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; |