如何使用QML Model,Delegate,Repeater,View?

时间:2017-12-12 10:31:13

标签: qt model delegates qml repeater

我有如下所示的json结果。在我的QML项目中,我想解析json,我帮助了How to show data in QML json request。现在我想设置4个标志。本地旗,美国,英国和欧洲在一排。我将添加如下所示。

我的问题是如何使用QML Model,Delegate,Repeater,View?哪种观点是更好的解决方案?

{ "tarih": "20171212", 
        "currency": { 
                "usa": { "buy": "3,7900", "sell": "3,8800", "e_buy": "3,7900" }, 
                "stg": { "buy": "5,0700", "sell": "5,1650", "e_buy": "5,0700" }, 
                "eur": { "buy": "4,4700", "sell": "4,5600", "e_buy": "4,4700" } 
                } 
} 

enter image description here

谢谢

更新:

最简单的方法是: 解析json与;

(var result = JSON.parse(request.responseText))

我得到了这个项目:

(getUsaBuy.text = result.currency.usa.buy)

1 个答案:

答案 0 :(得分:0)

我的帖子来自How to show data in QML json request

正在运行代码:

if (request.readyState === XMLHttpRequest.DONE) {
    if (request.status && request.status === 200) {
        var result = JSON.parse(request.responseText)
        // BUY
        textSTG_BUY.text = **result.currency.stg.buy**

        // SELL
        textSTG_SELL.text = **result.currency.stg.sell**

    }
    else {
        console.log("Log:", request.status, request.statusText)
    }
}