Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtQuick2: QAbstractListModel - passing object from C++ to QML [SOLVED]
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kappa
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kappa
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kumararajas
        wrote on last edited by
        #3

        The one who asked for the solution, gave answer. Thats cool :)

        --Kumar

        1 Reply Last reply
        0
        • M Offline
          M Offline
          messi
          wrote on last edited by
          #4

          Please add [SOLVED] to your thread title.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved