Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 2 Support (Qt 5) › My Model can't show rest of the data?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18808

    Niyazi

    Hi,

    My json’ gets 6 data always. But, I can show only first data. I am not be able to show rest of the data.

    Somewhere in my code something is missing. How do I show all the data in qml? Any help please?

     

    import Felgo 3.0
    import QtQuick 2.9
    import QtQuick.Layouts 1.3
    
    import "../singletons"
    
    Item {
        id: myWeatherItem
        anchors.horizontalCenter: parent.horizontalCenter
        width: CbStyle.appWidth - 25
        height:  CbStyle.appHeight * 0.27
        anchors.leftMargin: dp(5)
        anchors.rightMargin: dp(5)
    
        AppListView {
            id: weatherView
            anchors.fill: parent
            backgroundColor: "#00000000"
            model: ListModel { id: modelData }
            delegate: Item {
                id: myDelegate
                width: Math.max(110, myWeatherItem.width / weatherView.count)
                height: myWeatherItem.height
    
                // Content
                ColumnLayout {
                    anchors.fill: parent
                    anchors.topMargin: 10
                    anchors.bottomMargin: 10
    
                    // day
                    Text {
                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                        text:  model.day
                    }
    
                    // icon
                    Image {
                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                        scale: 0.75
                        source: model.iconText
                    }
    
                    // temperature
                    Text {
                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                        text: "%1˚C".arg(model.temperature)
                    }
    
                    // seperator
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
                        anchors.right: parent.right
                        width: 1
                        height: (myWeatherItem.height * 0.75)
                        color: "lightgrey"
                        // visible: model.index < weatherView.count - 1
                    }
                } // Contents
            } // delegate: Item
    
    
            Component.onCompleted: {
                var request = new XMLHttpRequest();
                request.open('GET', "https://query.*****************************", true);
                request.onreadystatechange = function() {
                    if (request.readyState === XMLHttpRequest.DONE) {
                        if (request.status && request.status === 200) {
                            var result = JSON.parse(request.responseText)
                            var list = result.query.results.channel.item.forecast //result[0]["forecast"];
                            for(var i in list) {
                                var getStatusIcon = list[i].code
                                modelData.append({ "day": list[i].day,
                                                 "iconText": "../../assets/weather/" + getStatusIcon + ".png",
                                                 "temperature": list[i].high
                                             });
                                console.log(i + ", Day:" + list[i].day + ", Temp:" + list[i].high + ", CurrentIconSet: " + getStatusIcon)
                                getStatusIcon = ""
                            } // for
                        }
                        else {
                            console.log("WeatherLog:", request.status, request.statusText)
                        }
                    } // if (request.readyState
                } // function
                request.send();
            }
    
        } // WeatherWidget
    } // myWeatherItem
    

     

    #18818

    Günther
    Felgo Team
    #18820

    Niyazi

    🙂 Thank you. I will post full code later with a new post

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded