Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. can't compare lists of my struct
Forum Updated to NodeBB v4.3 + New Features

can't compare lists of my struct

Scheduled Pinned Locked Moved Solved C++ Gurus
8 Posts 5 Posters 813 Views 3 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    This is what I'm trying to do:

    struct ValveConfiguration : public QObject {
        Q_OBJECT
    
        QUuid uuid;
        bool on;
        bool operator == (const ValveConfiguration &rhs) const {
            if (uuid == rhs.uuid && on == rhs.on)
                return true;
            return false;
        }
        bool operator != (const ValveConfiguration &rhs) const { return !(*this == rhs); }
    };
    
    class Outcome : public QObject
    {
        Q_OBJECT
        QList<ValveConfiguration> m_valveConfigurationList;
        bool setValveConfigurationList(const QList<ValveConfiguration> &list)
        {
            if (m_valveConfigurationList != list) { // getting an error here.
            ....
    

    I'm getting the following error:

    outcome.cpp:55:34: Invalid operands to binary expression ('QList<ValveConfiguration>' and 'const QList<ValveConfiguration>')
    qlist.h:333:56: candidate template ignored: requirement 'std::conjunction_v<std::disjunction<std::is_base_of<QList<ValveConfiguration>, ValveConfiguration>, QTypeTraits::has_operator_equal<ValveConfiguration>>>' was not satisfied [with U = ValveConfiguration]
    

    Can someone tell me what I'm doing wrong here? (The == operator fails, too.)

    Thanks...

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      This is what I'm trying to do:

      struct ValveConfiguration : public QObject {
          Q_OBJECT
      
          QUuid uuid;
          bool on;
          bool operator == (const ValveConfiguration &rhs) const {
              if (uuid == rhs.uuid && on == rhs.on)
                  return true;
              return false;
          }
          bool operator != (const ValveConfiguration &rhs) const { return !(*this == rhs); }
      };
      
      class Outcome : public QObject
      {
          Q_OBJECT
          QList<ValveConfiguration> m_valveConfigurationList;
          bool setValveConfigurationList(const QList<ValveConfiguration> &list)
          {
              if (m_valveConfigurationList != list) { // getting an error here.
              ....
      

      I'm getting the following error:

      outcome.cpp:55:34: Invalid operands to binary expression ('QList<ValveConfiguration>' and 'const QList<ValveConfiguration>')
      qlist.h:333:56: candidate template ignored: requirement 'std::conjunction_v<std::disjunction<std::is_base_of<QList<ValveConfiguration>, ValveConfiguration>, QTypeTraits::has_operator_equal<ValveConfiguration>>>' was not satisfied [with U = ValveConfiguration]
      

      Can someone tell me what I'm doing wrong here? (The == operator fails, too.)

      Thanks...

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

      @mzimmers said in can't compare lists of my struct:

      QList<ValveConfiguration>

      You can't copy objects derived from QObject so you won't be able to add anything to this container.

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

      1 Reply Last reply
      7
      • mzimmersM mzimmers

        Hi all -

        This is what I'm trying to do:

        struct ValveConfiguration : public QObject {
            Q_OBJECT
        
            QUuid uuid;
            bool on;
            bool operator == (const ValveConfiguration &rhs) const {
                if (uuid == rhs.uuid && on == rhs.on)
                    return true;
                return false;
            }
            bool operator != (const ValveConfiguration &rhs) const { return !(*this == rhs); }
        };
        
        class Outcome : public QObject
        {
            Q_OBJECT
            QList<ValveConfiguration> m_valveConfigurationList;
            bool setValveConfigurationList(const QList<ValveConfiguration> &list)
            {
                if (m_valveConfigurationList != list) { // getting an error here.
                ....
        

        I'm getting the following error:

        outcome.cpp:55:34: Invalid operands to binary expression ('QList<ValveConfiguration>' and 'const QList<ValveConfiguration>')
        qlist.h:333:56: candidate template ignored: requirement 'std::conjunction_v<std::disjunction<std::is_base_of<QList<ValveConfiguration>, ValveConfiguration>, QTypeTraits::has_operator_equal<ValveConfiguration>>>' was not satisfied [with U = ValveConfiguration]
        

        Can someone tell me what I'm doing wrong here? (The == operator fails, too.)

        Thanks...

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @mzimmers
        ...And further to @Christian-Ehrlicher, before you ask it is more usual to create lists of pointers to QObjects, QList<ValveConfiguration *>, which you can compare/copy....

        1 Reply Last reply
        4
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Also, inside of Q_OBJECT macro, there is a private: section, so anything you type after Q_OBJECT is private. You need to make it public:

          Q_OBJECT
          
          public:
          QUuid uuid;
              bool on;
              bool operator == (const ValveConfiguration &rhs) const {
                  if (uuid == rhs.uuid && on == rhs.on)
                      return true;
                  return false;
              }
              bool operator != (const ValveConfiguration &rhs) const { return !(*this == rhs); }
          

          (Z(:^

          Pl45m4P 1 Reply Last reply
          7
          • sierdzioS sierdzio

            Also, inside of Q_OBJECT macro, there is a private: section, so anything you type after Q_OBJECT is private. You need to make it public:

            Q_OBJECT
            
            public:
            QUuid uuid;
                bool on;
                bool operator == (const ValveConfiguration &rhs) const {
                    if (uuid == rhs.uuid && on == rhs.on)
                        return true;
                    return false;
                }
                bool operator != (const ValveConfiguration &rhs) const { return !(*this == rhs); }
            
            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @sierdzio said in can't compare lists of my struct:

            Also, inside of Q_OBJECT macro, there is a private: section, so anything you type after Q_OBJECT is private

            Since Q_OBJECT extends to

            #define Q_OBJECT \
            public: \
                QT_WARNING_PUSH \
                Q_OBJECT_NO_OVERRIDE_WARNING \
                static const QMetaObject staticMetaObject; \
                virtual const QMetaObject *metaObject() const; \
                virtual void *qt_metacast(const char *); \
                virtual int qt_metacall(QMetaObject::Call, int, void **); \
                QT_TR_FUNCTIONS \
            private: \
                Q_OBJECT_NO_ATTRIBUTES_WARNING \
                Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
                QT_WARNING_POP \
                struct QPrivateSignal { explicit QPrivateSignal() = default; }; \
                QT_ANNOTATE_CLASS(qt_qobject, "")
            

            and you usually use Q_OBJECT at the top of your class declaration.
            If you would switch the private: and public: section from the #define Q_OBJECT, which I initially thought would be a good idea, it would violate the C++ "standard" (common sense), because no access specifier in a C++ class means private:.

            Then, @mzimmers ' code would work as expected but you would ask yourself why :)
            I doubt people look at the Q_OBJECT code every day :)


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            2
            • mzimmersM mzimmers has marked this topic as solved on
            • mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #6

              Thanks for all the information, guys. Originally, I had declared the struct without deriving from QObject, and that didn't work, but I removed the QObject derivation, and now it seems to work.

              JonBJ Pl45m4P 2 Replies Last reply
              1
              • mzimmersM mzimmers

                Thanks for all the information, guys. Originally, I had declared the struct without deriving from QObject, and that didn't work, but I removed the QObject derivation, and now it seems to work.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @mzimmers Well, yes, because as @Christian-Ehrlicher said

                You can't copy objects derived from QObject

                So removing QObject from inherited class(es) will allow copying and your code to work. If you ever want to put QObject in again you'll have work with a list of pointers, QList<QObject *>.

                1 Reply Last reply
                1
                • mzimmersM mzimmers

                  Thanks for all the information, guys. Originally, I had declared the struct without deriving from QObject, and that didn't work, but I removed the QObject derivation, and now it seems to work.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by Pl45m4
                  #8

                  @mzimmers said in can't compare lists of my struct:

                  I removed the QObject derivation, and now it seems to work.

                  If you don't plan to ever use meta-object related stuff, then you really don't need a QObject derived class or the Q_OBJECT macro (for metacalls / qt signals).


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  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