Property Struct

template <typename T> struct Qul ::Property

The Property class can be used to hold a property of a given type. 更多...

Header: #include <qul/property.h>
Since: Qt Quick Ultralite 1.0

This struct was introduced in Qt Quick Ultralite 1.0.


特性 (const T & value )
特性 ()
void setValue (const T & v )
const T & value ()
const T & value () const


Use this class as a public member of objects you define in C++. They are then exposed as properties of that object in QML. Template parameter of the class defines the C++ type and is mapped to a corresponding QML type . Property type T that does not have built-in comparison operator must be provided with a user-defined operator==.

struct MyData : public Qul::Object
    Qul::Property<int> val;
    void update(int x)
        // can get and set property values from C++

The properties defined in C++ can be used in QML bindings.

Item {
    Item {
        // can bind QML property to exported property
        x: mydata_x.val
        color: "red"
        width: 50
        height: 50
    MyData {
        id: mydata_x
        val: 100
    MyData {
        id: mydata_width
        // can bind exported property
        val: parent.width
    Component.onCompleted: {

As you can see, QML bindings can be assigned to properties defined in C++. The value of the property will automatically update when the properties used in the binding change. They can also be used as sources when defining bindings in QML.

Grouped properties

Properties can be grouped together as follows:

struct MyObject : public Qul::Object
    struct Grouped
        Qul::Property<int> val1;
        Qul::Property<int> val2;
    Grouped group;

Then they can be used in QML like this:

Item {
    MyObject {
        group.val1: 42
        group.val2: 43

The grouping happens by placing the properties inside a struct or class S and then having a field of type S inside the exported class. The type S must not itself be derived from Qul::Object . Only its public fields of type Qul::Property are exposed as properties within the group.

另请参阅 特性 and Grouped properties .


Property:: 特性 (const T & value )

Creates a property initialized with value .

Property:: 特性 ()

Creates a property holding a zero-initialized value.

void Property:: setValue (const T & v )

Sets the value of this binding to v .

另请参阅 value ().

const T &Property:: value ()

Gets the value of this property.

另请参阅 setValue ().

const T &Property:: value () const