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 679 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.
  • M Online
    M Online
    mzimmers
    wrote on 31 May 2024, 02:58 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...

    C J 2 Replies Last reply 31 May 2024, 04:16
    0
    • M mzimmers
      31 May 2024, 02:58

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

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 31 May 2024, 04:16 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
      • M mzimmers
        31 May 2024, 02:58

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

        J Online
        J Online
        JonB
        wrote on 31 May 2024, 07:20 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
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 31 May 2024, 09:29 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(:^

          P 1 Reply Last reply 31 May 2024, 13:17
          7
          • S sierdzio
            31 May 2024, 09:29

            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); }
            
            P Online
            P Online
            Pl45m4
            wrote on 31 May 2024, 13:17 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
            • M mzimmers has marked this topic as solved on 31 May 2024, 15:40
            • M Online
              M Online
              mzimmers
              wrote on 31 May 2024, 15:42 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.

              J P 2 Replies Last reply 31 May 2024, 15:55
              1
              • M mzimmers
                31 May 2024, 15:42

                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.

                J Online
                J Online
                JonB
                wrote on 31 May 2024, 15:55 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
                • M mzimmers
                  31 May 2024, 15:42

                  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.

                  P Online
                  P Online
                  Pl45m4
                  wrote on 31 May 2024, 17:30 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

                  1/8

                  31 May 2024, 02:58

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved