Web API とやり取りして JSON でデータを取得する C++ コードがあり、JSON 応答は QML 側から問題なくアクセスできる変数に格納されます。カスタム コンポーネントを使用してこれらの JSON データを解析および表示できるようにしたいと考えています。JSON 項目ごとにこのコンポーネントの新しいインスタンスを作成し、それらをフリック可能に追加して、ユーザーがそれらをすべて表示できるようにしたいと考えています。
1.各ホールのデータを表示するための私のコンポーネント:
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. 取得した 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
}
]
私のmain.qmlには、Jsonを含む変数があり、上記のコンポーネントを取り込む予定のフリック可能があります.どうすればそれを達成できますか?
これらのホールを配列などに入れることができれば、特に C++ でそれを行うことができれば、簡単に行うことができます。