diff options
Diffstat (limited to 'examples/declarative/cppextensions/referenceexamples/attached')
3 files changed, 22 insertions, 21 deletions
diff --git a/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.h b/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.h index 02e9593b8b..c789c0bd51 100644 --- a/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.h +++ b/examples/declarative/cppextensions/referenceexamples/attached/birthdayparty.h @@ -75,12 +75,15 @@ public: int guestCount() const; Person *guest(int) const; + //! [static attached] static BirthdayPartyAttached *qmlAttachedProperties(QObject *); + //! [static attached] private: Person *m_host; QList<Person *> m_guests; }; +//! [declare attached] QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) - +//! [declare attached] #endif // BIRTHDAYPARTY_H diff --git a/examples/declarative/cppextensions/referenceexamples/attached/example.qml b/examples/declarative/cppextensions/referenceexamples/attached/example.qml index c21813ebf9..6a83af2804 100644 --- a/examples/declarative/cppextensions/referenceexamples/attached/example.qml +++ b/examples/declarative/cppextensions/referenceexamples/attached/example.qml @@ -40,32 +40,29 @@ import People 1.0 +//! [begin] BirthdayParty { - host: Boy { - name: "Bob Jones" - shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } - } +//! [begin] +//! [rsvp] + Boy { + name: "Robert Campbell" + BirthdayParty.rsvp: "2009-07-01" + } +//! [rsvp] // ![1] - Boy { - name: "Leo Hodges" + Boy { + name: "Leo Hodges" shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } BirthdayParty.rsvp: "2009-07-06" } // ![1] - Boy { - name: "Jack Smith" + Boy { + name: "Jack Smith" shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 } } - Girl { - name: "Anne Brown" - shoe.size: 7 - shoe.color: "red" - shoe.brand: "Marc Jacobs" - shoe.price: 699.99 - - BirthdayParty.rsvp: "2009-07-01" - } +//! [end] } +//! [end] diff --git a/examples/declarative/cppextensions/referenceexamples/attached/main.cpp b/examples/declarative/cppextensions/referenceexamples/attached/main.cpp index 21f076c3b7..4c2c3003fe 100644 --- a/examples/declarative/cppextensions/referenceexamples/attached/main.cpp +++ b/examples/declarative/cppextensions/referenceexamples/attached/main.cpp @@ -70,12 +70,13 @@ int main(int argc, char ** argv) for (int ii = 0; ii < party->guestCount(); ++ii) { Person *guest = party->guest(ii); + //! [query rsvp] QDate rsvpDate; - QObject *attached = - qmlAttachedPropertiesObject<BirthdayParty>(guest, false); + QObject *attached = qmlAttachedPropertiesObject<BirthdayParty>(guest, false); + if (attached) rsvpDate = attached->property("rsvp").toDate(); - + //! [query rsvp] if (rsvpDate.isNull()) qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; else |