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 derived class copy of
Qt 6.11 is out! See what's new in the release blog

QJsonObject derived class copy of

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 695 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    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.

    Kind Regards,
    Sy

    Christian EhrlicherC 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @SPlatten Your answer would imply that a compiler knows how to create a QLabel out of a QObject by itself.

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by SPlatten
      #5

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

      Kind Regards,
      Sy

      JonBJ 1 Reply Last reply
      0
      • SPlattenS SPlatten

        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.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #2

        @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?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        SPlattenS 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @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?

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #3

          @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 ?

          Kind Regards,
          Sy

          Christian EhrlicherC 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @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 EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @SPlatten Your answer would imply that a compiler knows how to create a QLabel out of a QObject by itself.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            SPlattenS 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @SPlatten Your answer would imply that a compiler knows how to create a QLabel out of a QObject by itself.

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #5

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

              Kind Regards,
              Sy

              JonBJ 1 Reply Last reply
              0
              • SPlattenS SPlatten has marked this topic as solved on
              • SPlattenS SPlatten

                @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;
                }
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @SPlatten
                I am not as expert at C++ as some, but I think you should write your operator = to take a const parameter for the QJsonObject& initialiser.

                SPlattenS 1 Reply Last reply
                2
                • JonBJ JonB

                  @SPlatten
                  I am not as expert at C++ as some, but I think you should write your operator = to take a const parameter for the QJsonObject& initialiser.

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  @JonB , thank you, will add that.

                  Kind Regards,
                  Sy

                  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