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 exploit a json file in QT ?
QtWS25 Last Chance

How to exploit a json file in QT ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
jsoncpp
28 Posts 4 Posters 4.7k 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.
  • jsulmJ jsulm

    @feedain You should really be more clear when asking.
    "How do i instanciate a new personnage with this json file ?" - do you mean you want to create an instance of a class and initialise its properties from values you read from a JSON file? If so then please tell us what exactly is not clear:

    1. How to read JSON file?
    2. How to initialise an instance of a class?
    F Offline
    F Offline
    feedain
    wrote on last edited by feedain
    #21

    @jsulm said in How to exploit a json file in QT ?:

    @feedain You should really be more clear when asking.
    "How do i instanciate a new personnage with this json file ?" - do you mean you want to create an instance of a class and initialise its properties from values you read from a JSON file? If so then please tell us what exactly is not clear:

    1. How to read JSON file?
    2. How to initialise an instance of a class?

    I will try to be more clear. I have created my JSON template which will have two parameters: the port number and the port state.
    So I have created the JSON file. But now I want to use it: let's say I want to set port 4 to state 1, how do I do that in QT? That's what I want to know, because with the debug, everything is fine, but now I want to exploit it according to the port number and the state of that port.

    jsulmJ 1 Reply Last reply
    0
    • F feedain

      @jsulm said in How to exploit a json file in QT ?:

      @feedain You should really be more clear when asking.
      "How do i instanciate a new personnage with this json file ?" - do you mean you want to create an instance of a class and initialise its properties from values you read from a JSON file? If so then please tell us what exactly is not clear:

      1. How to read JSON file?
      2. How to initialise an instance of a class?

      I will try to be more clear. I have created my JSON template which will have two parameters: the port number and the port state.
      So I have created the JSON file. But now I want to use it: let's say I want to set port 4 to state 1, how do I do that in QT? That's what I want to know, because with the debug, everything is fine, but now I want to exploit it according to the port number and the state of that port.

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

      @feedain

      1. Iterate over the objects in your array using https://doc.qt.io/qt-5/qjsonarray.html#operator-5b-5d
      2. For each object check the port whether it is the one you want to change (use https://doc.qt.io/qt-5/qjsonobject.html#operator-5b-5d)
      3. If you found the object, then change the State in that object (obj["State"] = int(state))

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

      F 1 Reply Last reply
      3
      • jsulmJ jsulm

        @feedain

        1. Iterate over the objects in your array using https://doc.qt.io/qt-5/qjsonarray.html#operator-5b-5d
        2. For each object check the port whether it is the one you want to change (use https://doc.qt.io/qt-5/qjsonobject.html#operator-5b-5d)
        3. If you found the object, then change the State in that object (obj["State"] = int(state))
        F Offline
        F Offline
        feedain
        wrote on last edited by
        #23

        @jsulm said in How to exploit a json file in QT ?:

        @feedain

        1. Iterate over the objects in your array using https://doc.qt.io/qt-5/qjsonarray.html#operator-5b-5d
        2. For each object check the port whether it is the one you want to change (use https://doc.qt.io/qt-5/qjsonobject.html#operator-5b-5d)
        3. If you found the object, then change the State in that object (obj["State"] = int(state))

        that's my code for create the JSON file :

            QJsonObject object;
            object.insert("port", QJsonValue(p));
            object.insert("etat",QJsonValue(e));
            QJsonDocument doc(object);
            qDebug() << doc.toJson();
        

        I don't use array, do i must use array ?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • F feedain

          @jsulm said in How to exploit a json file in QT ?:

          @feedain

          1. Iterate over the objects in your array using https://doc.qt.io/qt-5/qjsonarray.html#operator-5b-5d
          2. For each object check the port whether it is the one you want to change (use https://doc.qt.io/qt-5/qjsonobject.html#operator-5b-5d)
          3. If you found the object, then change the State in that object (obj["State"] = int(state))

          that's my code for create the JSON file :

              QJsonObject object;
              object.insert("port", QJsonValue(p));
              object.insert("etat",QJsonValue(e));
              QJsonDocument doc(object);
              qDebug() << doc.toJson();
          

          I don't use array, do i must use array ?

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

          @feedain said in How to exploit a json file in QT ?:

          I don't use array

          I'm getting tired.
          Above you shown us your JSON which was composed of an array containing objects.
          Could you please be so kind and explain to us how EXACTLY your JSON should look like?!
          Else we all are wasting time...

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

          F 1 Reply Last reply
          1
          • F feedain

            @jsulm said in How to exploit a json file in QT ?:

            @feedain

            1. Iterate over the objects in your array using https://doc.qt.io/qt-5/qjsonarray.html#operator-5b-5d
            2. For each object check the port whether it is the one you want to change (use https://doc.qt.io/qt-5/qjsonobject.html#operator-5b-5d)
            3. If you found the object, then change the State in that object (obj["State"] = int(state))

            that's my code for create the JSON file :

                QJsonObject object;
                object.insert("port", QJsonValue(p));
                object.insert("etat",QJsonValue(e));
                QJsonDocument doc(object);
                qDebug() << doc.toJson();
            

            I don't use array, do i must use array ?

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

            @feedain said in How to exploit a json file in QT ?:

            I don't use array, do i must use array ?

            If you want a whole lot of items and you don't use an array what else are you going to use? We have said several times it sounds like you want an array. It won't happen by magic.

            But please respond to @jsulm post above....

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @feedain said in How to exploit a json file in QT ?:

              I don't use array

              I'm getting tired.
              Above you shown us your JSON which was composed of an array containing objects.
              Could you please be so kind and explain to us how EXACTLY your JSON should look like?!
              Else we all are wasting time...

              F Offline
              F Offline
              feedain
              wrote on last edited by
              #26

              @jsulm said in How to exploit a json file in QT ?:

              @feedain said in How to exploit a json file in QT ?:

              I don't use array

              I'm getting tired.
              Above you shown us your JSON which was composed of an array containing objects.
              Could you please be so kind and explain to us how EXACTLY your JSON should look like?!
              Else we all are wasting time...

              Yes indeed I used an array above, but I don't want to use it as it is removed in the code.
              What I want to do is get an arduino port on QT and change its state without using array

              jsulmJ 1 Reply Last reply
              0
              • F feedain

                @jsulm said in How to exploit a json file in QT ?:

                @feedain said in How to exploit a json file in QT ?:

                I don't use array

                I'm getting tired.
                Above you shown us your JSON which was composed of an array containing objects.
                Could you please be so kind and explain to us how EXACTLY your JSON should look like?!
                Else we all are wasting time...

                Yes indeed I used an array above, but I don't want to use it as it is removed in the code.
                What I want to do is get an arduino port on QT and change its state without using array

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

                @feedain You already have this code snippet here, did you notice it?

                obj["State"] = int(state);
                

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

                F 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @feedain You already have this code snippet here, did you notice it?

                  obj["State"] = int(state);
                  
                  F Offline
                  F Offline
                  feedain
                  wrote on last edited by
                  #28

                  @jsulm said in How to exploit a json file in QT ?:

                  @feedain You already have this code snippet here, did you notice it?

                  obj["State"] = int(state);
                  

                  yes thanks

                  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