开发者

QML custom properties

开发者 https://www.devze.com 2023-01-24 14:34 出处:网络
I\'m having trouble defining a custom property in a QML item: Item { 开发者_JAVA技巧property MovieTileItem data

I'm having trouble defining a custom property in a QML item:

Item {
 开发者_JAVA技巧   property MovieTileItem data
    Text {
        text: "Some text"
    }
}

MovieTitleItem is an Item defined in a separate QML file :

import Qt 4.7

Item {
    property string title
    property string posterSource
}

The error I get is "Cannot assign object to property" pointing to the property declaration. Any ideas?


"Cannot assign object to property" because there is already such property as "data" (and it's read-only):

http://qt-project.org/doc/qt-4.8/qml-item.html#data-prop


I believe, custom types can not be used as property types if they are not registered with qmlRegisterType(). Following may probably achieve what you are looking for

Item {
    data:Custom{}
    Text {
        text: "Some text"
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消