aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/referenceexamples
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-08-21 18:34:21 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-09-26 12:32:17 +0200
commitcc1a604c704f848927b3fa0a97b0a50b0b79d2a4 (patch)
tree610ece713eba021c8e5a3d248f54a62370e810f8 /examples/qml/referenceexamples
parent531cf90305ae50920b2e597dd0758fdb82ad88b0 (diff)
Specify parameters of type registration in class declarations
Using this technique we can automatically register all necessary revisions and minor versions of a type, using the metaobject system. This greatly reduces the potential for mistakes and resulting incompatibilities between versions of imports. We assume that for each type we need to register all revisions of its super types and its attached type, and that the revisions match. That is, if you import version X of type A, you will also get version X of its attached type and of any super types. As we previously didn't take these dependencies into account when manually registering the types, a number of extra revisions are now registered for some types. Potentially, we can now generate the qmltypes files at compile time, using moc. Change-Id: I7abb8a5c39f5e63ad1a0cb41a783f2c91909491b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'examples/qml/referenceexamples')
-rw-r--r--examples/qml/referenceexamples/adding/main.cpp2
-rw-r--r--examples/qml/referenceexamples/adding/person.h3
-rw-r--r--examples/qml/referenceexamples/attached/birthdayparty.h10
-rw-r--r--examples/qml/referenceexamples/attached/main.cpp9
-rw-r--r--examples/qml/referenceexamples/attached/person.h5
-rw-r--r--examples/qml/referenceexamples/binding/birthdayparty.h5
-rw-r--r--examples/qml/referenceexamples/binding/main.cpp9
-rw-r--r--examples/qml/referenceexamples/binding/person.h5
-rw-r--r--examples/qml/referenceexamples/coercion/main.cpp8
-rw-r--r--examples/qml/referenceexamples/coercion/person.h6
-rw-r--r--examples/qml/referenceexamples/default/main.cpp5
-rw-r--r--examples/qml/referenceexamples/default/person.h4
-rw-r--r--examples/qml/referenceexamples/grouped/main.cpp6
-rw-r--r--examples/qml/referenceexamples/grouped/person.h5
-rw-r--r--examples/qml/referenceexamples/methods/main.cpp3
-rw-r--r--examples/qml/referenceexamples/methods/person.h2
-rw-r--r--examples/qml/referenceexamples/properties/main.cpp3
-rw-r--r--examples/qml/referenceexamples/properties/person.h2
-rw-r--r--examples/qml/referenceexamples/signal/birthdayparty.h4
-rw-r--r--examples/qml/referenceexamples/signal/main.cpp8
-rw-r--r--examples/qml/referenceexamples/signal/person.h5
-rw-r--r--examples/qml/referenceexamples/valuesource/birthdayparty.h4
-rw-r--r--examples/qml/referenceexamples/valuesource/main.cpp9
-rw-r--r--examples/qml/referenceexamples/valuesource/person.h5
24 files changed, 73 insertions, 54 deletions
diff --git a/examples/qml/referenceexamples/adding/main.cpp b/examples/qml/referenceexamples/adding/main.cpp
index 87a7b75764..ffd0e90c42 100644
--- a/examples/qml/referenceexamples/adding/main.cpp
+++ b/examples/qml/referenceexamples/adding/main.cpp
@@ -57,7 +57,7 @@ int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
//![0]
- qmlRegisterType<Person>("People", 1,0, "Person");
+ qmlRegisterTypesAndRevisions<Person>("People", 1);
//![0]
QQmlEngine engine;
diff --git a/examples/qml/referenceexamples/adding/person.h b/examples/qml/referenceexamples/adding/person.h
index f40c8d8086..530c335dee 100644
--- a/examples/qml/referenceexamples/adding/person.h
+++ b/examples/qml/referenceexamples/adding/person.h
@@ -51,12 +51,15 @@
#define PERSON_H
#include <QObject>
+#include <QtQml/qqml.h>
+
//![0]
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
+ QML_ELEMENT
public:
Person(QObject *parent = nullptr);
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);
};
diff --git a/examples/qml/referenceexamples/binding/birthdayparty.h b/examples/qml/referenceexamples/binding/birthdayparty.h
index 15e1908ece..3cd5cf1c9a 100644
--- a/examples/qml/referenceexamples/binding/birthdayparty.h
+++ b/examples/qml/referenceexamples/binding/birthdayparty.h
@@ -60,6 +60,7 @@ class BirthdayPartyAttached : public QObject
{
Q_OBJECT
Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged)
+ QML_ANONYMOUS
public:
BirthdayPartyAttached(QObject *object);
@@ -82,6 +83,8 @@ class BirthdayParty : public QObject
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement)
Q_CLASSINFO("DefaultProperty", "guests")
+ QML_ELEMENT
+ QML_ATTACHED(BirthdayPartyAttached)
public:
BirthdayParty(QObject *parent = nullptr);
@@ -107,6 +110,4 @@ private:
QList<Person *> m_guests;
};
-QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES)
-
#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/binding/main.cpp b/examples/qml/referenceexamples/binding/main.cpp
index eca524dfe2..8c6e3222d8 100644
--- a/examples/qml/referenceexamples/binding/main.cpp
+++ b/examples/qml/referenceexamples/binding/main.cpp
@@ -58,13 +58,8 @@
int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- qmlRegisterAnonymousType<BirthdayPartyAttached>("People", 1);
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
- qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong");
- qmlRegisterAnonymousType<ShoeDescription>("People", 1);
- qmlRegisterAnonymousType<Person>("People", 1);
- qmlRegisterType<Boy>("People", 1,0, "Boy");
- qmlRegisterType<Girl>("People", 1,0, "Girl");
+ qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, HappyBirthdaySong,
+ ShoeDescription, Person, Boy, Girl>("People", 1);
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
diff --git a/examples/qml/referenceexamples/binding/person.h b/examples/qml/referenceexamples/binding/person.h
index 543b24f971..af9864950a 100644
--- a/examples/qml/referenceexamples/binding/person.h
+++ b/examples/qml/referenceexamples/binding/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 NOTIFY shoeChanged)
Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged)
Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged)
+ QML_ANONYMOUS
public:
ShoeDescription(QObject *parent = nullptr);
@@ -91,6 +93,7 @@ class Person : public QObject
// ![0]
Q_PROPERTY(ShoeDescription *shoe READ shoe CONSTANT)
// ![0]
+ QML_ANONYMOUS
public:
Person(QObject *parent = nullptr);
@@ -109,6 +112,7 @@ private:
class Boy : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Boy(QObject * parent = nullptr);
};
@@ -116,6 +120,7 @@ public:
class Girl : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Girl(QObject * parent = nullptr);
};
diff --git a/examples/qml/referenceexamples/coercion/main.cpp b/examples/qml/referenceexamples/coercion/main.cpp
index 39064f8b89..2c2bd92e8d 100644
--- a/examples/qml/referenceexamples/coercion/main.cpp
+++ b/examples/qml/referenceexamples/coercion/main.cpp
@@ -58,16 +58,10 @@ int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
//![0]
- qmlRegisterAnonymousType<Person>("People", 1);
+ qmlRegisterTypesAndRevisions<BirthdayParty, Person, Boy, Girl>("People", 1);
//![0]
- //![register boy girl]
- qmlRegisterType<Boy>("People", 1,0, "Boy");
- qmlRegisterType<Girl>("People", 1,0, "Girl");
- //![register boy girl]
-
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
auto *party = qobject_cast<BirthdayParty *>(component.create());
diff --git a/examples/qml/referenceexamples/coercion/person.h b/examples/qml/referenceexamples/coercion/person.h
index 692cf4eb19..6865e0093a 100644
--- a/examples/qml/referenceexamples/coercion/person.h
+++ b/examples/qml/referenceexamples/coercion/person.h
@@ -51,12 +51,16 @@
#define PERSON_H
#include <QObject>
+#include <QtQml/qqml.h>
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
+ //![0]
+ QML_ANONYMOUS
+ //![0]
public:
Person(QObject *parent = nullptr);
@@ -75,6 +79,7 @@ private:
class Boy : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Boy(QObject * parent = nullptr);
};
@@ -83,6 +88,7 @@ public:
class Girl : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Girl(QObject * parent = nullptr);
};
diff --git a/examples/qml/referenceexamples/default/main.cpp b/examples/qml/referenceexamples/default/main.cpp
index f6ca77e82d..bbe4a239e2 100644
--- a/examples/qml/referenceexamples/default/main.cpp
+++ b/examples/qml/referenceexamples/default/main.cpp
@@ -58,10 +58,7 @@ int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
- qmlRegisterAnonymousType<Person>("People", 1);
- qmlRegisterType<Boy>("People", 1,0, "Boy");
- qmlRegisterType<Girl>("People", 1,0, "Girl");
+ qmlRegisterTypesAndRevisions<BirthdayParty, Person, Boy, Girl>("People", 1);
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
diff --git a/examples/qml/referenceexamples/default/person.h b/examples/qml/referenceexamples/default/person.h
index 87f69276bf..361a89c599 100644
--- a/examples/qml/referenceexamples/default/person.h
+++ b/examples/qml/referenceexamples/default/person.h
@@ -51,12 +51,14 @@
#define PERSON_H
#include <QObject>
+#include <QtQml/qqml.h>
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
+ QML_ANONYMOUS
public:
Person(QObject *parent = nullptr);
@@ -73,6 +75,7 @@ private:
class Boy : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Boy(QObject * parent = nullptr);
};
@@ -80,6 +83,7 @@ public:
class Girl : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Girl(QObject * parent = nullptr);
};
diff --git a/examples/qml/referenceexamples/grouped/main.cpp b/examples/qml/referenceexamples/grouped/main.cpp
index 4f4b828cef..e233aab5b1 100644
--- a/examples/qml/referenceexamples/grouped/main.cpp
+++ b/examples/qml/referenceexamples/grouped/main.cpp
@@ -58,11 +58,7 @@ int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- 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<BirthdayParty, ShoeDescription, Person, Boy, Girl>("People", 1);
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
diff --git a/examples/qml/referenceexamples/grouped/person.h b/examples/qml/referenceexamples/grouped/person.h
index 6f6caaee7c..df507c7386 100644
--- a/examples/qml/referenceexamples/grouped/person.h
+++ b/examples/qml/referenceexamples/grouped/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 = nullptr);
@@ -88,6 +90,7 @@ class Person : public QObject
// ![1]
Q_PROPERTY(ShoeDescription *shoe READ shoe)
// ![1]
+ QML_ANONYMOUS
public:
Person(QObject *parent = nullptr);
@@ -103,6 +106,7 @@ private:
class Boy : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Boy(QObject * parent = nullptr);
};
@@ -110,6 +114,7 @@ public:
class Girl : public Person
{
Q_OBJECT
+ QML_ELEMENT
public:
Girl(QObject * parent = nullptr);
};
diff --git a/examples/qml/referenceexamples/methods/main.cpp b/examples/qml/referenceexamples/methods/main.cpp
index e2a1a28c8b..4dd616f8cd 100644
--- a/examples/qml/referenceexamples/methods/main.cpp
+++ b/examples/qml/referenceexamples/methods/main.cpp
@@ -58,8 +58,7 @@ int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
- qmlRegisterType<Person>("People", 1,0, "Person");
+ qmlRegisterTypesAndRevisions<BirthdayParty, Person>("People", 1);
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
diff --git a/examples/qml/referenceexamples/methods/person.h b/examples/qml/referenceexamples/methods/person.h
index 749109dc72..2407fbb1b9 100644
--- a/examples/qml/referenceexamples/methods/person.h
+++ b/examples/qml/referenceexamples/methods/person.h
@@ -51,12 +51,14 @@
#define PERSON_H
#include <QObject>
+#include <QtQml/qqml.h>
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
+ QML_ELEMENT
public:
Person(QObject *parent = nullptr);
diff --git a/examples/qml/referenceexamples/properties/main.cpp b/examples/qml/referenceexamples/properties/main.cpp
index 60b56bd247..216869bf6c 100644
--- a/examples/qml/referenceexamples/properties/main.cpp
+++ b/examples/qml/referenceexamples/properties/main.cpp
@@ -59,8 +59,7 @@ int main(int argc, char ** argv)
QCoreApplication app(argc, argv);
//![register list]
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
- qmlRegisterType<Person>("People", 1,0, "Person");
+ qmlRegisterTypesAndRevisions<BirthdayParty, Person>("People", 1);
//![register list]
QQmlEngine engine;
diff --git a/examples/qml/referenceexamples/properties/person.h b/examples/qml/referenceexamples/properties/person.h
index 749109dc72..2407fbb1b9 100644
--- a/examples/qml/referenceexamples/properties/person.h
+++ b/examples/qml/referenceexamples/properties/person.h
@@ -51,12 +51,14 @@
#define PERSON_H
#include <QObject>
+#include <QtQml/qqml.h>
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
+ QML_ELEMENT
public:
Person(QObject *parent = nullptr);
diff --git a/examples/qml/referenceexamples/signal/birthdayparty.h b/examples/qml/referenceexamples/signal/birthdayparty.h
index 9aecc8929c..c815518291 100644
--- a/examples/qml/referenceexamples/signal/birthdayparty.h
+++ b/examples/qml/referenceexamples/signal/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,8 @@ 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
+ QML_ATTACHED(BirthdayPartyAttached)
public:
BirthdayParty(QObject *parent = nullptr);
@@ -97,6 +100,5 @@ private:
Person *m_host;
QList<Person *> m_guests;
};
-QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES)
#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/signal/main.cpp b/examples/qml/referenceexamples/signal/main.cpp
index f55b4cb419..f431e2bdc8 100644
--- a/examples/qml/referenceexamples/signal/main.cpp
+++ b/examples/qml/referenceexamples/signal/main.cpp
@@ -58,12 +58,8 @@ 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/signal/person.h b/examples/qml/referenceexamples/signal/person.h
index 06d4f2eb27..7283f39f61 100644
--- a/examples/qml/referenceexamples/signal/person.h
+++ b/examples/qml/referenceexamples/signal/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 = nullptr);
@@ -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);
};
diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.h b/examples/qml/referenceexamples/valuesource/birthdayparty.h
index 18a9b96147..25e2342937 100644
--- a/examples/qml/referenceexamples/valuesource/birthdayparty.h
+++ b/examples/qml/referenceexamples/valuesource/birthdayparty.h
@@ -60,6 +60,7 @@ class BirthdayPartyAttached : public QObject
{
Q_OBJECT
Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
+ QML_ANONYMOUS
public:
BirthdayPartyAttached(QObject *object);
@@ -79,6 +80,8 @@ class BirthdayParty : public QObject
Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement)
// ![0]
Q_CLASSINFO("DefaultProperty", "guests")
+ QML_ELEMENT
+ QML_ATTACHED(BirthdayPartyAttached)
public:
BirthdayParty(QObject *parent = nullptr);
@@ -102,6 +105,5 @@ private:
Person *m_host;
QList<Person *> m_guests;
};
-QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES)
#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/valuesource/main.cpp b/examples/qml/referenceexamples/valuesource/main.cpp
index ab50f00696..72e75fdea1 100644
--- a/examples/qml/referenceexamples/valuesource/main.cpp
+++ b/examples/qml/referenceexamples/valuesource/main.cpp
@@ -59,13 +59,8 @@ int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- qmlRegisterAnonymousType<BirthdayPartyAttached>("People", 1);
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
- qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong");
- qmlRegisterAnonymousType<ShoeDescription>("People", 1);
- qmlRegisterAnonymousType<Person>("People", 1);
- qmlRegisterType<Boy>("People", 1,0, "Boy");
- qmlRegisterType<Girl>("People", 1,0, "Girl");
+ qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, HappyBirthdaySong,
+ ShoeDescription, Person, Boy, Girl>("People", 1);
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
diff --git a/examples/qml/referenceexamples/valuesource/person.h b/examples/qml/referenceexamples/valuesource/person.h
index 06d4f2eb27..7283f39f61 100644
--- a/examples/qml/referenceexamples/valuesource/person.h
+++ b/examples/qml/referenceexamples/valuesource/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 = nullptr);
@@ -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);
};