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. Using ListModel inside C++ class.
Forum Updated to NodeBB v4.3 + New Features

Using ListModel inside C++ class.

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 5 Posters 4.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.
  • A Offline
    A Offline
    arno5m
    wrote on last edited by
    #1

    I !
    I can see there are several documentation about using a C++ model from within a .qml file.
    But I fail to found any 'reverse' sample :
    I'm creating a new Item by extending a QDeclarativeItem class, my item have a QVariant 'model' property.
    I'm able to import such item in a qml file and set the model property to a ListModel.
    What I can see debugging the write 'model' method from C++ code, is that model property is a: QVariant(QObject*, QDeclarativeListModel(0x10265aa70) )

    What I Can do with QDeclarativeListModel class ? which seems to be private part of QtDeclarative.
    (not included by "#include <QtDeclarative>", I failed to find any .h file for that class, the only reference I found on the web is a .../src/declarative/util/private/qdeclarativelistmodel_p_p.h)

    Is there a way to get the content of a ListModel from C++ source code ?
    (number of ListElement, access to role defined in list element, ...)

    Any example or suggestion is welcome, thanks a lot !
    Arnaud.

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

      Hi,

      Unfortunately it isn't really possible to use this class from C++ right now (it is based on the new list model interface developed for the itemviews-ng project, and is still private). This isn't ideal, and at some point all of our models should start using a public model class (either by making the new model interfaces public, or converting our models to use QAbstractItemModel).

      Regards,
      Michael

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtrahul
        wrote on last edited by
        #3

        Hi, arno

        You need one example , then see the below link :

        http://wiki.forum.nokia.com/index.php/Using_QML_ListView

        Best regards,

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

          [quote author="qtrahul" date="1292917569"]Hi, arno

          You need one example , then see the below link :

          http://wiki.forum.nokia.com/index.php/Using_QML_ListView

          Best regards,[/quote]
          How does that help the OP to access that model from C++?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            arno5m
            wrote on last edited by
            #5

            Really bad news to know it's not possible right now. I hope the ListModel and friends classes will be available at public level of QtQuick in next few release.

            @Andre: my purpose is to create a new visual item that behave like a popup menu", to compute size and to draw more complex shape than rectangle I need to create my own C++ class (like PieSlice example), but I want my menu to be populated by .qml side using : ListModel with element defining 'label' and 'id' roles (ie when user select a text the id is fired by a signal) and store in a PopupMenu.model property ... exactly as ListView does.

            Create that property as a QVariant works, assign it to a ListModel works, but debugging C++ side of my Item I can see the ListModel uses QDeclarativeListModel internal (private) class as qtrahul said.

            As a workaround for now, I create a C++ class for only the shape of my popup menu, and create a .qml that define texts and id. Which is strongly linked to the usage of this popupmenu in my qmlApp ... far from a reusable popupmenu component.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xsacha
              wrote on last edited by
              #6

              What shape is your pop-up menu by the way? You can achieve any shape using images. Is it that you want a non-rectangular mouseArea for the clicks? If so, yeah only C++ for that.

              Is there anything wrong with having the qml file define texts and ids? What do you need the C++ to do in this case? I have a log program that reads a text file and generates a list in C++ and passes it as a model in QML. The QML then interacts with the model and passes updated model back to the C++. Not sure if this is what you want.

              • Sacha
              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