QJsonObject derived class copy of
-
I have created a class which is derived from QJsonObject. I want to initialise the class from another instance of QJsonObject, however I'm getting errors.
The code:
QVariant varProperty(property(clsQtTable::mscszPropertyChanges)); Q_ASSERT_X(varProperty.isValid()==true, cszDebugName, "No changes property!"); //Initialise change management object mobjChangeMgnt = varProperty.toJsonObject();On the last lint the error displayed in Qt Creator:
clsQtTable.cpp:320: error: No viable overloaded '='My class prototype so far:
class clsQtProperties : public QJsonObject { private: bool blnFind(const QString& crstrKey, QJsonObject::Iterator& rIterator); public: static const char mscszKeyDelimiter[]; clsQtProperties(); bool blnCheckForChange(const QString& crstrKey, const QString& crstrData); bool blnGetFromKey(const QString& crstrKey, int& intColumn, QString& rstrPrimaryKey); bool blnSetData(const QString& crstrKey, const QString& crstrData ,bool blnInitial = false); static QString strBuildKey(int intColumn, const QString& crstrPrimaryKey); };This is the prototype for the class for mobjChangeMgnt.
-
@SPlatten Your answer would imply that a compiler knows how to create a QLabel out of a QObject by itself.
@Christian-Ehrlicher , fixed, modified prototype (Just new additions):
clsQtProperties(const QJsonObject& crobjOriginal); clsQtProperties operator = (QJsonObject& initialiser);Implementation:
clsQtProperties::clsQtProperties(const QJsonObject& crobjOriginal) { for( QJsonObject::const_iterator cit(crobjOriginal.begin()) ; cit!=crobjOriginal.end(); cit++ ) { insert(cit.key(), cit.value()); } } clsQtProperties clsQtProperties::operator= (const QJsonObject& crobjInitialiser) { *this = clsQtProperties(crobjInitialiser); return *this; } -
I have created a class which is derived from QJsonObject. I want to initialise the class from another instance of QJsonObject, however I'm getting errors.
The code:
QVariant varProperty(property(clsQtTable::mscszPropertyChanges)); Q_ASSERT_X(varProperty.isValid()==true, cszDebugName, "No changes property!"); //Initialise change management object mobjChangeMgnt = varProperty.toJsonObject();On the last lint the error displayed in Qt Creator:
clsQtTable.cpp:320: error: No viable overloaded '='My class prototype so far:
class clsQtProperties : public QJsonObject { private: bool blnFind(const QString& crstrKey, QJsonObject::Iterator& rIterator); public: static const char mscszKeyDelimiter[]; clsQtProperties(); bool blnCheckForChange(const QString& crstrKey, const QString& crstrData); bool blnGetFromKey(const QString& crstrKey, int& intColumn, QString& rstrPrimaryKey); bool blnSetData(const QString& crstrKey, const QString& crstrData ,bool blnInitial = false); static QString strBuildKey(int intColumn, const QString& crstrPrimaryKey); };This is the prototype for the class for mobjChangeMgnt.
@SPlatten said in QJsonObject derived class copy of:
No viable overloaded '='
Then you should create this overload (and for design reason also a ctor taking a QJsonObject) . How should the compiler know how to convert from one type into the other otherwise?
-
@SPlatten said in QJsonObject derived class copy of:
No viable overloaded '='
Then you should create this overload (and for design reason also a ctor taking a QJsonObject) . How should the compiler know how to convert from one type into the other otherwise?
@Christian-Ehrlicher , I thought because the class prototype states it is derived from QJsonObject that the compiler would know this from the prototype?
Can you help me with how or what I need to do ?
-
@Christian-Ehrlicher , I thought because the class prototype states it is derived from QJsonObject that the compiler would know this from the prototype?
Can you help me with how or what I need to do ?
@SPlatten Your answer would imply that a compiler knows how to create a QLabel out of a QObject by itself.
-
@SPlatten Your answer would imply that a compiler knows how to create a QLabel out of a QObject by itself.
@Christian-Ehrlicher , fixed, modified prototype (Just new additions):
clsQtProperties(const QJsonObject& crobjOriginal); clsQtProperties operator = (QJsonObject& initialiser);Implementation:
clsQtProperties::clsQtProperties(const QJsonObject& crobjOriginal) { for( QJsonObject::const_iterator cit(crobjOriginal.begin()) ; cit!=crobjOriginal.end(); cit++ ) { insert(cit.key(), cit.value()); } } clsQtProperties clsQtProperties::operator= (const QJsonObject& crobjInitialiser) { *this = clsQtProperties(crobjInitialiser); return *this; } -
S SPlatten has marked this topic as solved on
-
@Christian-Ehrlicher , fixed, modified prototype (Just new additions):
clsQtProperties(const QJsonObject& crobjOriginal); clsQtProperties operator = (QJsonObject& initialiser);Implementation:
clsQtProperties::clsQtProperties(const QJsonObject& crobjOriginal) { for( QJsonObject::const_iterator cit(crobjOriginal.begin()) ; cit!=crobjOriginal.end(); cit++ ) { insert(cit.key(), cit.value()); } } clsQtProperties clsQtProperties::operator= (const QJsonObject& crobjInitialiser) { *this = clsQtProperties(crobjInitialiser); return *this; } -
@SPlatten
I am not as expert at C++ as some, but I think you should write youroperator =to take aconstparameter for theQJsonObject& initialiser.