diff options
Diffstat (limited to 'examples/qml/referenceexamples/grouped')
5 files changed, 14 insertions, 10 deletions
diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.cpp b/examples/qml/referenceexamples/grouped/birthdayparty.cpp index 1bae55076c..81db8ab1b8 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.cpp +++ b/examples/qml/referenceexamples/grouped/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/grouped/birthdayparty.h b/examples/qml/referenceexamples/grouped/birthdayparty.h index edaa11fa88..f6834dad89 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.h +++ b/examples/qml/referenceexamples/grouped/birthdayparty.h @@ -60,6 +60,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/grouped/grouped.pro b/examples/qml/referenceexamples/grouped/grouped.pro index ef66ea3e1d..1513ac552d 100644 --- a/examples/qml/referenceexamples/grouped/grouped.pro +++ b/examples/qml/referenceexamples/grouped/grouped.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/grouped/main.cpp b/examples/qml/referenceexamples/grouped/main.cpp index 14cd64fe68..63dbe988a4 100644 --- a/examples/qml/referenceexamples/grouped/main.cpp +++ b/examples/qml/referenceexamples/grouped/main.cpp @@ -58,12 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - 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")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -87,9 +81,9 @@ int main(int argc, char ** argv) if (bestShoe) qWarning() << bestShoe->name() << "is wearing the best shoes!"; - } else { - qWarning() << component.errors(); + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } 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); }; |