Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML custom properties

Tags:

qt4

qml

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?

like image 434
Yulia Rogovaya Avatar asked Oct 17 '25 00:10

Yulia Rogovaya


2 Answers

"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

like image 129
Tomasz Elendt Avatar answered Oct 18 '25 17:10

Tomasz Elendt


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"
    }
}
like image 41
Gorkem Ercan Avatar answered Oct 18 '25 16:10

Gorkem Ercan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!