Qt5 official demo consumer set 24 -- extending qml-default property example

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.