Qt5 XmlListModel nested data



  • I have an xml file and I want to load it with xmllistmodel. The data structure is similiar to the code below.

    @
    <itemA>
    <settings> </settings>
    <ItembArray>
    <itemB>
    <settings>
    </settings>
    ...
    <ItemC>
    ...
    </ItemC>
    <ItemC>
    ...
    </ItemC>
    </itemB>
    ...
    <itemB>

      ...
    <ItemC>
     ...
    </ItemC>
    <ItemC>
     ...
    </ItemC>
    

    </itemB>
    </ItembArray>
    </itemA>
    @

    because xmllistmodel can only work as list model, so I want to add 3 views, viewA, ViewB , ViewC, and for each view , there is an xmlListModel, eg. modelA -> viewA, modelB -> viewB, modelC -> viewC. 
    I can set the same source for ModelA, ModelB, ModelC and use different query to get the data, but I think this is slow , because I need to open this xml file for many times, (viewA with many ViewBs and ViewB with many ViewCs), 
    So I think may I use model like this
    

    @
    modelA{
    id: modelA
    source: test.xml
    role1: itemA/settings
    role2: itemA/ItembArray
    }

    modelB{
        xml: modelA.get(0).role2
        role1: itemB/settings
        role2: itemB/ItemC
    }
    

    @

    but I don't know how to get the xml source code with XmlRole, is my way correct?



  • In other words, how can I get the original xml source code from XmlRole so I can set this as other model's xml property.


Log in to reply
 

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