Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to assign ListModel's data to JsonObj in JS
Qt 6.12 LTS is out! See what's new in the release blog

How to assign ListModel's data to JsonObj in JS

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 747 Views 2 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.
  • A Offline
    A Offline
    Anas A. Ismail
    wrote on last edited by p3c0
    #1

    Hi everyone,
    How to assign ListModel's data to JsonObj in JS code to be saved to JSON file
    I made something like this

    ListModel{
    id: jsonDataModel;
    }
    JsonStorage{
    //registered type
    id: jsonStorage
    fileName: "db"
    }
    
    function savJSON()
    {
    var jsonObj = listModel // here's the problem, how this assignment could be made ?
    var data = JSON.stringify(jsonObj)
    jsonStorage.save(data)
    

    }

    p3c0P 1 Reply Last reply
    0
    • A Anas A. Ismail

      Hi everyone,
      How to assign ListModel's data to JsonObj in JS code to be saved to JSON file
      I made something like this

      ListModel{
      id: jsonDataModel;
      }
      JsonStorage{
      //registered type
      id: jsonStorage
      fileName: "db"
      }
      
      function savJSON()
      {
      var jsonObj = listModel // here's the problem, how this assignment could be made ?
      var data = JSON.stringify(jsonObj)
      jsonStorage.save(data)
      

      }

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

      @Anas-A.-Ismail Assign the ListModel's id to that variable. Then you will need to iterate the model and stringify the individual data. Eg.:

      var model = jsonDataModel
      for(var a=0; a<model.count; a++) {
          console.log(JSON.stringify(model.get(a)))
      }
      

      Then you can somehow aggregate all the data into a single string and pass it to your function.

      157

      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
      • Unsolved