Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to fetch multiple children inside a parent in Treewidget

How to fetch multiple children inside a parent in Treewidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 316 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pappu Kumar Keshari
    wrote on last edited by
    #1

    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);
    }
    }

    JonBJ 1 Reply Last reply
    0
    • P Pappu Kumar Keshari

      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);
      }
      }

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved