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. Creating a QAbstractItemModel plugin object from QML?
Forum Updated to NodeBB v4.3 + New Features

Creating a QAbstractItemModel plugin object from QML?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 3.9k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    GordonSchumacher
    wrote on last edited by
    #1

    I have written a C++ plug-in which defines a data model derived from QAbstractListModel. My QML code is successfully loading the plugin; that part of the code actually works...

    The documentation suggests that it is possible to define the model class in C++, export it via the plugin interface, then actually create the model and populate it from the QML side.

    I have the following QML code:
    @import QtQuick 1.0
    import MyModelPlugin 1.0

    ListView {
    id: list
    width: 640; height: 480;
    model: MyListModel {
    ListElement {source: "element 1";}
    ListElement {source: "element 2";}
    }
    delegate: Text { text: source; }
    }@

    When I run this, however, I receive:

    @file:///home/gordons/build/testapp/Debug/qml/testapp/main.qml:8:8: Cannot assign to non-existent default property
    ListElement {source: "element 1";}
    ^@

    I believe this is what the documentation indicates I should be doing; has anyone managed to make this work?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Could you show the pertinent C++ parts too please?

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbrasser
        wrote on last edited by
        #3

        Hi,

        If you haven't seen it yet, I'd suggest looking at http://doc.trolltech.com/4.7-snapshot/qdeclarativemodels.html for more information/examples on using C++ models from QML.

        It currently isn't possible to populate a QAbstractItemModel from QML out-of-the-box -- you'll need to add your own custom methods/properties to support that (ListElement only works with ListModel).

        Regards,
        Michael

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GordonSchumacher
          wrote on last edited by
          #4

          I got it working, actually - it was several arcane bits which all needed to be used together. I'll put the solution up on a wiki page or some such once I get it into order. (And yes, it even works with ListElement!)

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            Cool stuff. That would be good to see.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Indeed! Looking forward to seeing your magic, Gordon!

              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