aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/referenceexamples/binding
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml/referenceexamples/binding')
-rw-r--r--examples/qml/referenceexamples/binding/binding.pro4
-rw-r--r--examples/qml/referenceexamples/binding/birthdayparty.cpp2
-rw-r--r--examples/qml/referenceexamples/binding/birthdayparty.h5
-rw-r--r--examples/qml/referenceexamples/binding/example.qml2
-rw-r--r--examples/qml/referenceexamples/binding/happybirthdaysong.h3
-rw-r--r--examples/qml/referenceexamples/binding/main.cpp13
-rw-r--r--examples/qml/referenceexamples/binding/person.h5
7 files changed, 20 insertions, 14 deletions
diff --git a/examples/qml/referenceexamples/binding/binding.pro b/examples/qml/referenceexamples/binding/binding.pro
index 636d0a10f1..dce780d0a2 100644
--- a/examples/qml/referenceexamples/binding/binding.pro
+++ b/examples/qml/referenceexamples/binding/binding.pro
@@ -1,5 +1,9 @@
QT += qml
+CONFIG += qmltypes
+QML_IMPORT_NAME = People
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += main.cpp \
person.cpp \
birthdayparty.cpp \
diff --git a/examples/qml/referenceexamples/binding/birthdayparty.cpp b/examples/qml/referenceexamples/binding/birthdayparty.cpp
index 866c1f6968..cfedf84be0 100644
--- a/examples/qml/referenceexamples/binding/birthdayparty.cpp
+++ b/examples/qml/referenceexamples/binding/birthdayparty.cpp
@@ -87,7 +87,7 @@ void BirthdayParty::setHost(Person *c)
QQmlListProperty<Person> BirthdayParty::guests()
{
- return QQmlListProperty<Person>(this, m_guests);
+ return QQmlListProperty<Person>(this, &m_guests);
}
int BirthdayParty::guestCount() const
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/example.qml b/examples/qml/referenceexamples/binding/example.qml
index a89b4bc02e..b45ef6881b 100644
--- a/examples/qml/referenceexamples/binding/example.qml
+++ b/examples/qml/referenceexamples/binding/example.qml
@@ -62,7 +62,7 @@ BirthdayParty {
shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
}
// ![0]
- onPartyStarted: console.log("This party started rockin' at " + time);
+ onPartyStarted: (time) => { console.log("This party started rockin' at " + time); }
Boy {
diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.h b/examples/qml/referenceexamples/binding/happybirthdaysong.h
index dcfebc06ba..c84e9d9e5e 100644
--- a/examples/qml/referenceexamples/binding/happybirthdaysong.h
+++ b/examples/qml/referenceexamples/binding/happybirthdaysong.h
@@ -52,14 +52,17 @@
#include <QQmlPropertyValueSource>
#include <QQmlProperty>
+#include <qqml.h>
#include <QStringList>
+#include <qqml.h>
class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_INTERFACES(QQmlPropertyValueSource)
+ QML_ELEMENT
public:
HappyBirthdaySong(QObject *parent = nullptr);
diff --git a/examples/qml/referenceexamples/binding/main.cpp b/examples/qml/referenceexamples/binding/main.cpp
index 99187eba3e..2e9995fcd8 100644
--- a/examples/qml/referenceexamples/binding/main.cpp
+++ b/examples/qml/referenceexamples/binding/main.cpp
@@ -58,13 +58,6 @@
int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- qmlRegisterType<BirthdayPartyAttached>();
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
- qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong");
- qmlRegisterType<ShoeDescription>();
- qmlRegisterType<Person>();
- qmlRegisterType<Boy>("People", 1,0, "Boy");
- qmlRegisterType<Girl>("People", 1,0, "Girl");
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
@@ -94,9 +87,9 @@ int main(int argc, char ** argv)
}
party->startParty();
- } else {
- qWarning() << component.errors();
+ return QCoreApplication::exec();
}
- return app.exec();
+ qWarning() << component.errors();
+ return EXIT_FAILURE;
}
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);
};