QtQuick2: QAbstractListModel - passing object from C++ to QML [SOLVED]
I have a project, which is well working in Qt 4.8, but I need to port it to the new version of Qt - 5.1.
- I have a class CControl derived from QObject and having a few properties defined by Q_PROPERTY macro. It is registered wit qmlRegisterType.
- I have the CListModel class, which derives from QAbstractListModel and from QList<CControl*> and I'm using it to pass data for the list defined in QML.
- I have defined a role ItemRole (named item).
- When I access it from QML, I just pass (in data() method) my CControl object like this:
When I try to access the ItemRole from QML like this:
@property CControl control: item@
I get an error: Unable to assign ObjectsList_QMLTYPE_102 to CControl.
Sorry, my fault. I have commented setRoleNames() at the beginning of porting as it was not compiling :)
Just overriden roleNames and it's fine now.
The one who asked for the solution, gave answer. Thats cool :)
Please add [SOLVED] to your thread title.