[SOLVED] How to retrieve data from a XmlListModel to another XmlListModel?



  • Hey, I want to call a data from a XmlListModel to another XmlListModel which is in a different page.
    Here are my codes

    @ //Page1
    XmlListModel {
    id: products1
    property string feedUrl: ""
    property bool loading: status == XmlListModel.Loading

        source: "http://appsfactory.my/client/canonmsia2/android/fws/products1.php"
        query: "/plist/dict/array/dict"
    
        XmlRole { name: "icon1"; query: "string[1]/string()" }
        XmlRole { name: "category1"; query: "string[2]/string()" }
        XmlRole { name: "products2"; query: "string[3]/string()" } //want to make this as source in Page2
    

    }

    ListView {
        id: list1
        anchors {
            left: parent.left
            right: parent.right
            top: parent.top
            bottom: parent.bottom
            rightMargin:8
            leftMargin:5
            topMargin: header.height + headBar.height + (window.height > 640 ? 270 : 210)
        }
        clip: true
        model: products1
        delegate: listDelegate1
    }
    
    Component {
        id: listDelegate1
    
        Products1Item{
            icon_p1_item: icon1;
            category_p1_item: category1
    
            onClicked:
            {
                 Util.log("Clicked on " + products2 + " product1")
                 Util.log("Selected feed item" + products2);
                 pageStack.push(Qt.resolvedUrl("Page2.qml"));
            }
    
        }
    }
    

    //Page2

    XmlListModel {
        id: products2
        property string feedUrl: ""
        property bool loading: status == XmlListModel.Loading
    
        source: " "  //products2 from XmlListModel in Page1
        query: "/plist/dict/array/dict"
    
        XmlRole { name: "icon2"; query: "string[1]/string()" }
        XmlRole { name: "category2"; query: "string[2]/string()" }
        XmlRole { name: "products3"; query: "string[3]/string()" }
    

    }

    @

    I want to place products2 from the first XmlListModel(Page1) as a source in the 2nd XmlListModel (Page2).
    I hope I am clear enough. Can anyone teach me how to do it?

    i tried this source : products1.get(0).products2 but can't work.



  • It's okay I figured it out.
    On clicked i should put it like this,

    @ //Page1
    pageStack.push(Qt.resolvedUrl("Page2.qml"), {itemUrl2:products2, itemTitle2:category1})
    //set the properties in the bracket, linking to the name in the XmlListModel

    //Page2
    Page {
    id: container2
    property string itemUrl2: "" //set the property here
    property string itemTitle2: ""

    orientationLock: PageOrientation.LockPortrait
    FontLoader { id: fixedFont; source: "../fonts/CANON.ttf"}
    

    //---------------------------------xml----------------------------------------------
    XmlListModel {
    id: products2
    property string feedUrl: ""
    property bool loading: status == XmlListModel.Loading

        source: itemUrl2 //put the itemUrl2 here as source
        query: "/plist/dict/array/dict"
    
        XmlRole { name: "icon2"; query: "string[1]/string()" }
        XmlRole { name: "category2"; query: "string[2]/string()" }
        XmlRole { name: "products3"; query: "string[3]/string()" }
    

    }
    @

    Found this from, http://harmattan-dev.nokia.com/docs/library/html/qt-components/qt-components-meego-pagestack.html under Advanced Usage.

    Can use both of these ways for deep linking.
    @pageStack.push
    ([
    { page: pageOne, properties: { one: 1 } },
    { page: Qt.resolvedUrl("two.qml"), properties: { two: 2 }},
    ]);

    //or this
    pageStack.push(Qt.resolvedUrl("foo.qml"), {foo: bar, foz: baz }); @


Log in to reply
 

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