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. QQmlPropertyMap model
Qt 6.11 is out! See what's new in the release blog

QQmlPropertyMap model

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 929 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.
  • S Offline
    S Offline
    sBoff
    wrote on last edited by
    #1

    Hi all,

    I'm trying to get my head around this and after much research and testing I feel I must be missing something simple.

    I have a QQmlPropertyMap derived object that I am adding to in my C++ code. I am then binding to the data in my QML - this is all working great. When I update the value on the C++ side my UI also updates.

    C++ side:
    @
    // Set the 'runtime' Context Property, this is my QQmlPropertyMap derived object
    Runtime rt;
    rt.GetData()->insert("abc", 120);
    rt.GetData()->insert("xyz", 65);
    view.rootContext()->setContextProperty("runtime", &rt);
    @

    QML side:
    @
    MyQmlObject
    {
    value: runtime.data.abc
    }
    @

    This next part is where I'm getting stuck/confused.. I want to have a QML table that displayes all the key/values in the property map and automatically updates. How do I go about this? I cant find any examples that use the QQmlPropertyMap as a model for a TableView or any other view.

    @
    TableView
    {
    anchors.fill: parent
    model: runtime.model // ????
    }
    @

    Basically what I've done for the time being is created a QAbstractTableModel derived object that takes my QQmlPropertyMap object as a paramater. This enables me to expose a QAbstractTableModel to my QML and for the data to be correct however, when it came to the stage of having to update the data I need to do 'tricks' to get the QAbstractTableModel updated in sync with the QQmlPropertyMap. If i have to manually keep a QAbstractTableModel in sync with a QQmlPropertyMap this completly negates me using a QQmlPropertyMap in the first place (which was to easily update my UI as the data changes).

    Surely there must be a simple way I'm not aware of? How can I use a QQmlPropertyMap as the model for the QML TableView?

    Thanks

    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