Yulia Rogovaya
Yulia Rogovaya

Reputation: 934

QML custom properties

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

Item {
    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?

Upvotes: 4

Views: 12393

Answers (2)

Tomasz Elendt
Tomasz Elendt

Reputation: 1485

"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

Upvotes: 7

Gorkem Ercan
Gorkem Ercan

Reputation: 3226

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"
    }
}

Upvotes: 1

Related Questions