How to fetch muliple children inside a parents which belongs to same parent. In TreeWidget .
-
Json Format data is in this format: ->
[ { "classification" : "Interaction-based", "subClassification" : [ " Automatic DefusionClose", "Autonatic Defusion" ] }, { "classification" : "Fishing nets", "subClassification" : [ " Identity of fishing nets", "Identity out" ] }, { "classification" : "Restricted/Critical Area", "subClassification" : [ " Restricted area entry", "EEZ area entry", "TW area entry" ] }, { "classification" : "Position", "subClassification" : [ " Spoofing", "RADAR-AIS", "RADAR-GPS", "AIS-MSIG ] } ]
Acoording to this code every time parent is also comming as total number of child. But I want to Similar child should come inside unique parent. Like classification should be parent and subClassification should be child inside parent in tree widget. Please help me and reply as soon as possible
QEventLoop entLoop eventLoop; QNetworkAccessManager mgr; QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)),&eventLoop,SLOT(quit())); QNetworkRequest req(QUrl(QString("http://182.178.7.22.8082/"))); QNetworkReply *reply = mgr.get(req); eventLoop.exec(); if(reply->error() == QNetworkReply::NoError) { QString data = reply->readAll(); QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8()); QJsonArray array = doc.array(); for (int i = 0; i < array.size(); i++) { QJsonObject object = array.at(i).toObject(); QVariantMap map = object.toVariantMap(); QString classification = map["classification"].toString(); QString subClassification = map["subClassification"].toString(); QTreeWidgetItem *parent = new QTreeWidgetItem(ui->parentTableWidget); QTreeWidgetItem *child = new QTreeWidgetItem(ui->childTableWidget); parent->setText(0,classification); child->setText(0,classification); QTreeWidgetItem *sub_Item = new QTreeWidgetItem(parent); sub_Item->setText(0,subClassification); } }
-
Hi and welcome to devnet,
You have to keep a map of the classification and corresponding item.
Then for each element you parse, check if the parent already exist in the map. If not, create a new item and put it in the map. If it does exist, retrieve it and use it. -
Please send code. And if require any modification in my code then please change and send code to me.
-
Please send code. And if require any modification in my code then please change and send code to me.
@Pappu-Kumar-Keshari
You will find we do not write code for people :) We are a user forum where people ask questions and other people suggest approaches, but the original person still needs to write the code. @SGaist has indicated how he would do it if he were you. Why don't you have a go at implementing it yourself, it's pretty clear and straightforward from his instructions? -
Hi and welcome to devnet,
You have to keep a map of the classification and corresponding item.
Then for each element you parse, check if the parent already exist in the map. If not, create a new item and put it in the map. If it does exist, retrieve it and use it.@SGaist HI, please send the full code and if require to change in my code then reply after changing. I will wait for you reply more eagerly.
Please send code -
@Pappu-Kumar-Keshari
You will find we do not write code for people :) We are a user forum where people ask questions and other people suggest approaches, but the original person still needs to write the code. @SGaist has indicated how he would do it if he were you. Why don't you have a go at implementing it yourself, it's pretty clear and straightforward from his instructions?@JonB said in How to fetch muliple children inside a parents which belongs to same parent. In TreeWidget .:
@Pappu-Kumar-Keshari
You will find we do not write code for people :) We are a user forum where people ask questions and other people suggest approaches, but the original person still needs to write the code. @SGaist has indicated how he would do it if he were you. Why don't you have a go at implementing it yourself, it's pretty clear and straightforward from his instructions?As @JonB wrote, this is a user forum, not a free code writing service. If you need someone to do the implementation and bug fix of your code for you then please hire a professional.