How to fetch multiple children inside a 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 possibleQEventLoop 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);
}
} -
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 possibleQEventLoop 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);
}
}@Pappu-Kumar-Keshari
So this is the identical question to your one in https://forum.qt.io/topic/141394/how-to-fetch-muliple-children-inside-a-parents-which-belongs-to-same-parent-in-treewidget, only laid out worse? Please don't double-post, it wastes the efforts of those trying to answer.You have the required answer there from @SGaist. Posting the same question a second time will not alter that.