2

I have a C++ code that interacts with a web API to get some data in JSON, then the JSON response is stored in a variable that can be accessed from the QML side with no issues. I want to be able to parse and show these JSON data using a custom component, I want to create a new instance of this component for each JSON item then add them to a flickable so the user can see them all.

1. My Component for showing each hall's data:

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1

Item {
    id: root
    width: 250

    property alias id: id.text
    property alias name: name.text
    property alias status: status.text
    property alias statusReason: statusReason.text
    property alias comments: comments.text

    ColumnLayout {
        id: mainLayout

        RowLayout {
            id: first

            Label {
                text: "المُعرِّف :  "
            }

            Label {
                id: id
                text: "N/A"
            }
        }

        RowLayout {
            id: second

            Label {
                text: "القاعة :  "
            }

            Label {
                id: name
                text: "N/A"
            }
        }

        RowLayout {
            Label {
                text: "الحالة :  "
            }

            Label {
                id: status
                text: "N/A"
            }
        }

        RowLayout {
            Label {
                text: "السبب :  "
            }

            Label {
                id: statusReason
                text: "N/A"
            }
        }

        RowLayout {
            Label {
                text: "تعليقات :  "
            }

            Label {
                id: comments
                text: "N/A"
            }
        }
    }
}

2. The fetched JSON ( Halls info ):

[
  {
    "Id": 1,
    "Name": "The Biggest Hall",
    "Status": "Busy",
    "StatusReason": "Lecture with Dr. Sami Elderdery",
    "Comments": "The current lecture will finish at 11 AM."
  },
  {
    "Id": 2,
    "Name": "Eltijany Yousuf Bashier",
    "Status": "Unoccupied",
    "StatusReason": null,
    "Comments": null
  }
]

In my main.qml I have a variable containing the Json & I have a flickable which I intend to populate with the component above, how can I achieve that?

If I could get these halls into an array or something it would be an easy-to-do job especially if I could do it in C++.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Alaa Salah
  • 1,047
  • 3
  • 12
  • 28

0 Answers0