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 insert entry to json file
Forum Updated to NodeBB v4.3 + New Features

How to insert entry to json file

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 6 Posters 2.4k 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.
  • L lukutis222

    @JonB

    Thanks for clarifying regarding the order.

    Yes I now realize that I created QJsonDocument using commandsArray that I modified and it does not contain the main JsonObject "commands" . I have try to check if the change I made to commandsArray affect jsonresponse but unfortunately it does not.

    I looked up how to add jsonarray inside another json object here (for java language):
    https://stackoverflow.com/questions/12142238/add-jsonarray-to-jsonobject

    and they use put() method, so something like:

    QJsonObject jsonobject;
    jsonobject.put("commands", commandsArray);
    

    Unfortunately, QT does not have this method and I was not able to find a relevant method for adding a QJsonArray inside another QJsonObject.

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

    @lukutis222

    I looked up how to add jsonarray inside another json object here (for java language):

    I am lost. You are not trying to add a new array inside anything, you are trying to add a new element to an existing array. As for looking at Java, that won't get you anywhere :)

    I have try to check if the change I made to commandsArray affect jsonresponse but unfortunately it does not.

    I don't think this is correct, but I do not have time right now to check. I suggest you try a tiny example to verify this.

    Works without any issues. The file now contains everything:

    OK, so you are good now anyway!

    1 Reply Last reply
    0
    • L lukutis222

      @ChrisW67 Ahh thanks for clarifying regarding the fileseek.

      Also, the file size (in lines) can be much bigger than 100. This is just an example

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #22

      @lukutis222 said in How to insert entry to json file:

      Also, the file size (in lines) can be much bigger than 100. This is just an example

      That may be so, but your code created an array of 100 QStrings to load the lines into:

       int line_count=0;
      QString line[100];
      ...
      while( !in.atEnd())
          {
              line[line_count]=in.readLine();
              line_count++;
          }
      

      It does not seem to me that this will handle a file with 101 lines.

      1 Reply Last reply
      2

      • Login

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