All articles in this series can be viewed here in http://blog.csdn.net/cloud_castle/article/category/2123873
Link to qt5 official demo release set 23 -- extending qml-inheritance and coercion example
Sometimes we can see that some data in the declaration of a qml type is not placed after Attribute +:. They actually belong to the default attribute of this type. This demo introduces this technology to us.
This example is almost unchanged from the previous one, except for two small points.
The first is example. qml in the qml description file:
Import people 1.0 //! [0] birthdayparty {Host: Boy {name: "Bob Jones" shoesize: 12} Boy {name: "Leo Hodges"} // unlike the previous one, these three persons are not placed in guests. Boy {Name: "Jack Smith"} // but their values are assigned the default property "guests" girl {name: "Anne Brown "}}//! [0]
The other part is our birthdayparty class declaration, birthdayparty. h:
# Ifndef birthdayparty_h # define birthdayparty_h # include <qobject> # include <qqmllistproperty> # include "person. H "//! [0] class birthdayparty: Public qobject {q_object q_property (person * Host read host write sethost) q_property (qqmllistproperty <person> guests read guests) q_classinfo ("defaultproperty", "guests ") // The q_classinfo macro is used to add additional information to the class public: // and the information can be added to the meta object information of the class birthdayparty (qobject * parent = 0 ); // here, a default attribute "guests" person * Host () const; void sethost (person *); qqmllistproperty <person> Gu is added for the birthdayparty class. ESTs (); int guestcount () const; person * guest (INT) const; private: person * m_host; qlist <person *> m_guests ;};//! [0] # endif // birthdayparty_h