QJsonObject troubles



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



  • 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;
    }


  • 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;
    }



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.