Extending QML - Default Property Example¶
Default Property.
This example builds on:
The Default Property Example is a minor modification of the Extending QML - Inheritance and Coercion Example that simplifies the specification of a BirthdayParty through the use of a default property.
<Code snippet "referenceexamples/default/example.qml:0" not found>
Declaring the BirthdayParty Class¶
The only difference between this example and the last, is the addition of the DefaultProperty
class info annotation.
<Code snippet "referenceexamples/default/birthdayparty.h:0" not found>
The default property specifies the property to assign to whenever an explicit property is not specified, in the case of the BirthdayParty type the guest property. It is purely a syntactic simplification, the behavior is identical to specifying the property by name, but it can add a more natural feel in many situations. The default property must be either an object or list property.
Running the Example¶
The main.cpp file in the example includes a simple shell application that loads and runs the QML snippet shown at the beginning of this page.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.