QQmlPropertyMap model



  • 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


Log in to reply
 

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