Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Serializing QList<Custom> to JSON data Qt
Forum Updated to NodeBB v4.3 + New Features

Serializing QList<Custom> to JSON data Qt

Scheduled Pinned Locked Moved Installation and Deployment
1 Posts 1 Posters 1.8k 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.
  • A Offline
    A Offline
    adityaram89
    wrote on last edited by
    #1

    Hi I am trying to convert the object into JSON. In that process i have created 2 classes.
    @
    class class1 : Public object
    {
    Q_OBJECT

    Q_PROPERTY(QString Item1 READ getItem1 WRITE setItem1)
    Q_PROPERTY(qint64 Item2 READ getItem2 WRITE setItem2)
    

    private:

    QString Item1;
    qint64 Item2;
    

    public:

    QString getItem1 () const { return Item1;}
    
    void setItem1 (const QString& Item){ Item1= Item; }
    

    // In the same way i have it for item2

    }

    Q_DECLARE_METATYPE(class1*);

    Class class2 : public QObject
    {

    Q_OBJECT
    
    Q_PROPERTY(QString Item1 READ getItem1 WRITE setItem1)
    Q_PROPERTY(qint64 Item2 READ getItem2 WRITE setItem2)
    Q_PROPERTY(QList<Class1*> class1List READ getclass1List WRITE setclass1List)
    

    private:
    qint64 Item5;
    qint64 Item6;
    QList< class1* > class1List;

    public:

    QString getItem5 () const { return Item5;}
    
    void setItem5 (const QString& Item){ Item5 = Item; }
    
    QString getItem6 () const { return Item6;}
    
    void setItem6 (const QString& Item){ Item6 = Item; }
    
    const QList<class1*> &getclass1List() const { return class1List;}
    
    void setclass1List(const QList<class1List*> &List) { class1List= List; }
    

    @
    Now i have converted the class2 object which has class1 list into QVariant using QJson::QObjectHelper::qobject2qvariant, All the data inside class2 is converted to JSON, but the list is printed as NULL.

    Please let me know what is wrong in this procedure.

    I have also tried it with
    @
    QList<class1*> getclass1List() const { return class1List;}

    void setclass1List(const QList<class1List*> List) { class1Lis = List; }
    @

    But no Use... i am still getting NULL for the value of list in JSON object. If i print the same list as a separate object, i am getting the data.

    [Added @ around code. andreyc]

    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