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 muliple children inside a parents which belongs to same parent. In TreeWidget .
Forum Updated to NodeBB v4.3 + New Features

How to fetch muliple children inside a parents which belongs to same parent. In TreeWidget .

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 449 Views 1 Watching
  • 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 Chris Kawa
    #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);
            }
        }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      1
      • P Offline
        P Offline
        Pappu Kumar Keshari
        wrote on last edited by
        #3

        Please send code. And if require any modification in my code then please change and send code to me.

        JonBJ 1 Reply Last reply
        0
        • P Pappu Kumar Keshari

          Please send code. And if require any modification in my code then please change and send code to me.

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

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

          SGaistS 1 Reply Last reply
          0
          • SGaistS SGaist

            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.

            P Offline
            P Offline
            Pappu Kumar Keshari
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            0
            • JonBJ JonB

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

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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