aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/referenceexamples/default
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml/referenceexamples/default')
-rw-r--r--examples/qml/referenceexamples/default/birthdayparty.cpp2
-rw-r--r--examples/qml/referenceexamples/default/birthdayparty.h1
-rw-r--r--examples/qml/referenceexamples/default/default.pro4
-rw-r--r--examples/qml/referenceexamples/default/main.cpp12
-rw-r--r--examples/qml/referenceexamples/default/person.h4
5 files changed, 14 insertions, 9 deletions
diff --git a/examples/qml/referenceexamples/default/birthdayparty.cpp b/examples/qml/referenceexamples/default/birthdayparty.cpp
index 1bae55076c..81db8ab1b8 100644
--- a/examples/qml/referenceexamples/default/birthdayparty.cpp
+++ b/examples/qml/referenceexamples/default/birthdayparty.cpp
@@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c)
QQmlListProperty<Person> BirthdayParty::guests()
{
- return {this, m_guests};
+ return {this, &m_guests};
}
int BirthdayParty::guestCount() const
diff --git a/examples/qml/referenceexamples/default/birthdayparty.h b/examples/qml/referenceexamples/default/birthdayparty.h
index ea63a6a16d..5eb6c88763 100644
--- a/examples/qml/referenceexamples/default/birthdayparty.h
+++ b/examples/qml/referenceexamples/default/birthdayparty.h
@@ -61,6 +61,7 @@ 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
public:
BirthdayParty(QObject *parent = nullptr);
diff --git a/examples/qml/referenceexamples/default/default.pro b/examples/qml/referenceexamples/default/default.pro
index c119ef0d2e..f52f749ddd 100644
--- a/examples/qml/referenceexamples/default/default.pro
+++ b/examples/qml/referenceexamples/default/default.pro
@@ -1,5 +1,9 @@
QT = core 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/default/main.cpp b/examples/qml/referenceexamples/default/main.cpp
index 017d6495cd..6b47d0d4c4 100644
--- a/examples/qml/referenceexamples/default/main.cpp
+++ b/examples/qml/referenceexamples/default/main.cpp
@@ -58,11 +58,6 @@ int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
- qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty");
- qmlRegisterType<Person>();
- qmlRegisterType<Boy>("People", 1,0, "Boy");
- qmlRegisterType<Girl>("People", 1,0, "Girl");
-
QQmlEngine engine;
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
auto *party = qobject_cast<BirthdayParty *>(component.create());
@@ -77,9 +72,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/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);
};