Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Json Parsing and comparing the values

Json Parsing and comparing the values

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 683 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.
  • S Offline
    S Offline
    Stephen28
    wrote on last edited by
    #1

    Hi all,
    I have json format like this->
    {
    "id": 7,
    "sort_decs": "Identity",
    "last_name": "Lawson",
    },
    {
    "id": 8,
    "sort_decs": "Identity",
    "last_name": "Ferguson",
    },
    {
    "id": 9,
    "sort_decs": "Identity",
    "last_name": "Funke",
    },
    {
    "id": 10,
    "sort_decs": "Identity",
    "last_name": "Fields",
    },
    {
    "id": 11,
    "sort_decs": "Identity",
    "last_name": "Edwards",
    }

    In qtreewidget how can I get sort_desc value for parent1 and last_name in its childs. if the sort_decs value is repeated how can get it only once in parent1 and last_name 's in childs .

    JonBJ 1 Reply Last reply
    0
    • S Stephen28

      Hi all,
      I have json format like this->
      {
      "id": 7,
      "sort_decs": "Identity",
      "last_name": "Lawson",
      },
      {
      "id": 8,
      "sort_decs": "Identity",
      "last_name": "Ferguson",
      },
      {
      "id": 9,
      "sort_decs": "Identity",
      "last_name": "Funke",
      },
      {
      "id": 10,
      "sort_decs": "Identity",
      "last_name": "Fields",
      },
      {
      "id": 11,
      "sort_decs": "Identity",
      "last_name": "Edwards",
      }

      In qtreewidget how can I get sort_desc value for parent1 and last_name in its childs. if the sort_decs value is repeated how can get it only once in parent1 and last_name 's in childs .

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

      @Stephen28
      Before I try to answer: you say qtreewidget but you have posted this in QML and Qt Quick. Are you indeed asking about QTreeWidget which is a Qt widget, not QML?

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @Stephen28
        Before I try to answer: you say qtreewidget but you have posted this in QML and Qt Quick. Are you indeed asking about QTreeWidget which is a Qt widget, not QML?

        S Offline
        S Offline
        Stephen28
        wrote on last edited by
        #3

        @JonB I not understanding terms clearly bro, since I was new to qt not only qt but for It field.

        jsulmJ 1 Reply Last reply
        0
        • S Stephen28

          @JonB I not understanding terms clearly bro, since I was new to qt not only qt but for It field.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Stephen28 The point is: you posted in "QML and Qt Quick" forum but you're talking about QTreeWidget which is QtWidgets not QML/QtQuick. You should post in correct forum.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Stephen28 said in Json Parsing and comparing the values:

            you should also look up json itself, this is far from a valid json. file


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • S Offline
              S Offline
              Stephen28
              wrote on last edited by
              #6

              Any one help me to resolve this one

              J.HilkJ JonBJ 2 Replies Last reply
              0
              • S Stephen28

                Any one help me to resolve this one

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Stephen28 you have to help us first, before we can help you.
                You haven't even bothered to answer the QWidget VS QML question yet.

                I can give you this link, so you can start fixing your json string at least


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1
                • S Stephen28

                  Any one help me to resolve this one

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

                  @Stephen28 said in Json Parsing and comparing the values:

                  Any one help me to resolve this one

                  @JonB said in Json Parsing and comparing the values:

                  @Stephen28
                  Before I try to answer: you say qtreewidget but you have posted this in QML and Qt Quick. Are you indeed asking about QTreeWidget which is a Qt widget, not QML?

                  Nobody can answer till we know which you are targeting. If using Qt you have to know whether you chose to use widgets vs QML. Look it up/Google it is you don't know what this is about.

                  As an outline approach: having read in your JSON (Qt QJson... classes, Python json module, whichever) you will want to transform your data from how it is now --- "flat" records/objects --- into a tree hierarchy, where items are parents and children. You need a single parent for "sort_decs": "Identity" and that have multiple children for items ("id": 7, "last_name": "Lawson"), ("id": 8, "last_name": "Ferguson"), etc. That gives you your tree structure.

                  You will need to recognise that "sort_decs": "Identity" occurs multiple times and create just one parent node for all of those. You will probably want a Qt QMap or C++ std::map for this, so that you can easily spot the same value for the various objects and re-use the single parent node for them. Depending, you might do this directly into the QTreeWidget if you don't want to re-map the input objects, or you might populate the QTreeWidget from your separately-built tree map hierarchy.

                  1 Reply Last reply
                  0

                  • Login

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