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. QJsonObject troubles
Qt 6.11 is out! See what's new in the release blog

QJsonObject troubles

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.0k 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.
  • G Offline
    G Offline
    gpioloco
    wrote on last edited by
    #1

    First i am using the following configuration :

    Qt 5.8.0 MinGW 32 bit

    My problem is caused in the following situation.

    QJsonObject objA = someClass->m_objB;
    

    Where someClass contains a QJsonObject with 4 values. The values are correctly displayed in the Locals and Expressions Window.
    So according to the doc :
    http://doc.qt.io/qt-5/qjsonobject.html#operator-eq
    the = operator should assign m_objB to objA.
    But after the execution objA still contains 0 items / values. And i can't figure out why

    Thank you for your help.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      you are not using operator= you are using the copy constructor but it's pretty irrelevant, it should work. Can you try this minimal example:

      #include <QJsonObject>
      #include <QJsonValue>
      #include <QDebug>
      struct SomeClass{
      QJsonObject m_objB;
      };
      int main(){
      SomeClass someClass;
      someClass.m_objB["foo"]=1;
      someClass.m_objB["bar"]=2;
      qDebug() << someClass.m_objB;
      QJsonObject objA =someClass.m_objB;
      qDebug() << objA;
      return 0;
      }

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • G Offline
        G Offline
        gpioloco
        wrote on last edited by
        #3

        Your code example works i will try to find the diffrences between my code and comment back as soon as i got new results.
        @VRonin said in QJsonObject troubles:

        #include <QJsonObject>
        #include <QJsonValue>
        #include <QDebug>
        struct SomeClass{
        QJsonObject m_objB;
        };
        int main(){
        SomeClass someClass;
        someClass.m_objB["foo"]=1;
        someClass.m_objB["bar"]=2;
        qDebug() << someClass.m_objB;
        QJsonObject objA =someClass.m_objB;
        qDebug() << objA;
        return 0;
        }

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gpioloco
          wrote on last edited by
          #4

          Ok i found the problem, everything is working fine now.
          The problem was that the values were only set in the derived class(SomeClass) and not in the base class(SomeBaseClass).
          Thank you for your help anyway

          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