Results 1 to 2 of 2

Thread: How to assign ListModel's data to JsonObj in JS

  1. #1
    Join Date
    Nov 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to assign ListModel's data to JsonObj in JS

    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)
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to assign ListModel's data to JsonObj in JS

    You probably have to iterate over the model entries and create a JS array containing the entries.

    Or you implement a model that can deal with the JSON directly, i.e. a bit like XmlListModel.

    Cheers,
    _

Similar Threads

  1. listmodel
    By ganeshgladish in forum Newbie
    Replies: 1
    Last Post: 2nd July 2013, 12:55
  2. ListElement refer ListModel id
    By keolsen in forum Qt Quick
    Replies: 0
    Last Post: 13th November 2012, 10:23
  3. Custom ListModel and QML
    By kernel_panic in forum Qt Quick
    Replies: 1
    Last Post: 8th November 2012, 08:02
  4. QML ListModel for interaction with C++
    By shock in forum Qt Quick
    Replies: 23
    Last Post: 21st March 2012, 23:42
  5. A simplest ListModel... no example :(
    By tomek in forum Newbie
    Replies: 5
    Last Post: 7th January 2006, 00:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.