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. Error when making "QObject::connect"
Forum Updated to NodeBB v4.3 + New Features

Error when making "QObject::connect"

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.4k Views
  • 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.
  • C Offline
    C Offline
    Creatorczyk
    wrote on last edited by
    #1

    Hi,

    I want to create a simple class inheriting from QList but while creating the line, from connect returns an error:

    Error:

    C:\Qt\Qt5.12.5\5.12.5\mingw73_64\include\QtCore\qobject.h:250: error: no matching function for call to 'QObject::connectImpl(const Object*&, void**, const Object*&, void**, QtPrivate::QSlotObject<void (AssetsList::*)(), QtPrivate::List<>, void>*, Qt::ConnectionType&, const int*&, const QMetaObject*)'
             return connectImpl(sender, reinterpret_cast<void **>(&signal),
                    ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                receiver, reinterpret_cast<void **>(&slot),
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                new QtPrivate::QSlotObject<Func2, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotType::ArgumentCount>::Value,
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                typename SignalType::ReturnType>(slot),
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                 type, types, &SignalType::Object::staticMetaObject);
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    C:\Qt\Qt5.12.5\5.12.5\mingw73_64\include\QtCore\qobjectdefs_impl.h:414: error: invalid static_cast from type 'QObject*' to type 'QtPrivate::FunctionPointer<void (AssetsList::*)()>::Object* {aka AssetsList*}'
                     FuncType::template call<Args, R>(static_cast<QSlotObject*>(this_)->function, static_cast<typename FuncType::Object *>(r), a);
                                                                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    My code:

    class AssetsList: public QList<Asset>{
        Q_OBJECT
    public:
        AssetsList(): actionsValue(0), bondsValue(0), rawMaterialsValue(0){
            QObject::connect(this, &AssetsList::test_signal, this, &AssetsList::test_slot);
        }
        virtual ~AssetsList(){}
    
    signals:
        void test_signal();
    
    public slots:
        void test_slot(){
            /* do something*/
        }
    
    private:
        float actionsValue;
        float bondsValue;
        float rawMaterialsValue;
    };
    

    How could i fix that?

    jsulmJ 1 Reply Last reply
    0
    • C Creatorczyk

      Hi,

      I want to create a simple class inheriting from QList but while creating the line, from connect returns an error:

      Error:

      C:\Qt\Qt5.12.5\5.12.5\mingw73_64\include\QtCore\qobject.h:250: error: no matching function for call to 'QObject::connectImpl(const Object*&, void**, const Object*&, void**, QtPrivate::QSlotObject<void (AssetsList::*)(), QtPrivate::List<>, void>*, Qt::ConnectionType&, const int*&, const QMetaObject*)'
               return connectImpl(sender, reinterpret_cast<void **>(&signal),
                      ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  receiver, reinterpret_cast<void **>(&slot),
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  new QtPrivate::QSlotObject<Func2, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotType::ArgumentCount>::Value,
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                  typename SignalType::ReturnType>(slot),
                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                   type, types, &SignalType::Object::staticMetaObject);
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      C:\Qt\Qt5.12.5\5.12.5\mingw73_64\include\QtCore\qobjectdefs_impl.h:414: error: invalid static_cast from type 'QObject*' to type 'QtPrivate::FunctionPointer<void (AssetsList::*)()>::Object* {aka AssetsList*}'
                       FuncType::template call<Args, R>(static_cast<QSlotObject*>(this_)->function, static_cast<typename FuncType::Object *>(r), a);
                                                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      

      My code:

      class AssetsList: public QList<Asset>{
          Q_OBJECT
      public:
          AssetsList(): actionsValue(0), bondsValue(0), rawMaterialsValue(0){
              QObject::connect(this, &AssetsList::test_signal, this, &AssetsList::test_slot);
          }
          virtual ~AssetsList(){}
      
      signals:
          void test_signal();
      
      public slots:
          void test_slot(){
              /* do something*/
          }
      
      private:
          float actionsValue;
          float bondsValue;
          float rawMaterialsValue;
      };
      

      How could i fix that?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Creatorczyk https://doc.qt.io/qt-5/qobject.html#Q_OBJECT
      "Note: This macro requires the class to be a subclass of QObject. Use Q_GADGET instead of Q_OBJECT to enable the meta object system's support for enums in a class that is not a QObject subclass."
      Try to change Q_OBJECT to Q_GADGET because QList is not derived from QObject.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Creatorczyk
        wrote on last edited by
        #3

        @jsulm I changed like below:

        class AssetsList: public QList<Asset>{
            Q_GADGET
        public:
            AssetsList(): actionsValue(0), bondsValue(0), rawMaterialsValue(0){
                QObject::connect(this, &AssetsList::test_signal, this, &AssetsList::test_slot);
            }
            virtual ~AssetsList(){}
        
        signals:
            void test_signal();
        
        public slots:
            void test_slot(){
        
            }
        
        private:
            float actionsValue;
            float bondsValue;
            float rawMaterialsValue;
        };
        

        But there are still errors:

        error: 'qt_metacall' is not a member of 'AssetsList'
                 enum { Value =  sizeof(test(&Object::qt_metacall)) == sizeof(int) };
                                             ^~~~~~~
        
        error: static assertion failed: No Q_OBJECT in the class with the signal
         #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
        
        error: static assertion failed: No Q_OBJECT in the class with the signal
         #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                                                         ^
        
        jsulmJ 1 Reply Last reply
        0
        • C Creatorczyk

          @jsulm I changed like below:

          class AssetsList: public QList<Asset>{
              Q_GADGET
          public:
              AssetsList(): actionsValue(0), bondsValue(0), rawMaterialsValue(0){
                  QObject::connect(this, &AssetsList::test_signal, this, &AssetsList::test_slot);
              }
              virtual ~AssetsList(){}
          
          signals:
              void test_signal();
          
          public slots:
              void test_slot(){
          
              }
          
          private:
              float actionsValue;
              float bondsValue;
              float rawMaterialsValue;
          };
          

          But there are still errors:

          error: 'qt_metacall' is not a member of 'AssetsList'
                   enum { Value =  sizeof(test(&Object::qt_metacall)) == sizeof(int) };
                                               ^~~~~~~
          
          error: static assertion failed: No Q_OBJECT in the class with the signal
           #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
          
          error: static assertion failed: No Q_OBJECT in the class with the signal
           #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                                                           ^
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Creatorczyk My bad: "Q_GADGETs can have Q_ENUM, Q_PROPERTY and Q_INVOKABLE, but they cannot have signals or slots."
          https://doc.qt.io/qt-5/qobject.html#Q_GADGET
          So, my suggestion is not going to work as you want to have signals/slots.
          Is there a reason why you want to subclass QList?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          2
          • jsulmJ jsulm

            @Creatorczyk My bad: "Q_GADGETs can have Q_ENUM, Q_PROPERTY and Q_INVOKABLE, but they cannot have signals or slots."
            https://doc.qt.io/qt-5/qobject.html#Q_GADGET
            So, my suggestion is not going to work as you want to have signals/slots.
            Is there a reason why you want to subclass QList?

            C Offline
            C Offline
            Creatorczyk
            wrote on last edited by
            #5

            @jsulm I would like to inherit from QList to add my methods and to be able to pass a list to a model in a ListView in qml

            VRoninV 1 Reply Last reply
            0
            • C Creatorczyk

              @jsulm I would like to inherit from QList to add my methods and to be able to pass a list to a model in a ListView in qml

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @Creatorczyk Isn't it easier if you derive from QAbstractListModel?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              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