QtQuick2: QAbstractListModel - passing object from C++ to QML [SOLVED]



  • Hello.
    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.

    1. I have a class CControl derived from QObject and having a few properties defined by Q_PROPERTY macro. It is registered wit qmlRegisterType.
    2. 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.
    3. I have defined a role ItemRole (named item).
    4. When I access it from QML, I just pass (in data() method) my CControl object like this:
      @return QVariant::fromValue<CControl*>(ctrl);@

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.