aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/referenceexamples/coercion
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml/referenceexamples/coercion')
-rw-r--r--examples/qml/referenceexamples/coercion/main.cpp15
-rw-r--r--examples/qml/referenceexamples/coercion/person.h6
2 files changed, 11 insertions, 10 deletions
diff --git a/examples/qml/referenceexamples/coercion/main.cpp b/examples/qml/referenceexamples/coercion/main.cpp
index 262cdf6320..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]
- qmlRegisterType<Person>();
+ 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());
@@ -82,9 +76,10 @@ int main(int argc, char ** argv)
for (int ii = 0; ii < party->guestCount(); ++ii)
qWarning() << " " << party->guest(ii)->name();
- } else {
- qWarning() << component.errors();
+
+ return EXIT_SUCCESS;
}
- return 0;
+ qWarning() << component.errors();
+ return EXIT_FAILURE;
}
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);
};