Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt6 regression with QAbstractListModel? Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined

Qt6 regression with QAbstractListModel? Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined

Scheduled Pinned Locked Moved Solved Qt 6
7 Posts 2 Posters 2.1k 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.
  • mbruelM Offline
    mbruelM Offline
    mbruel
    wrote on last edited by mbruel
    #1

    Hi,
    I'm migrating my projects to Qt6 because it seems to be mandatory in order to publish on Apple Store... (to do so we need iOS sdk 14 which is not supported by Qt 5.15 :'( ) Anyway that's not the topic of this thread...

    So basically most of my models (inheriting from QAbstractListModel) are constructed using a pointer on my main app QObject that is kind of a "Controller". cf my RemoteFileModel that hold a pointer on ClementineRemote
    This was documented in few places as the way to use Models in Qt.

    But now Qt6 is asking for a full defined object for pointers in Q_PROPERTY.

    In file included from /opt/Qt/6.1.2/macos/lib/QtCore.framework/Headers/QAbstractListModel:1:
    In file included from /opt/Qt/6.1.2/macos/lib/QtCore.framework/Headers/qabstractitemmodel.h:46:
    In file included from /opt/Qt/6.1.2/macos/lib/QtCore.framework/Headers/qobject.h:54:
    /opt/Qt/6.1.2/macos/lib/QtCore.framework/Headers/qmetatype.h:778:23: error: invalid application of 'sizeof' to an incomplete type 'ClementineRemote'
            static_assert(sizeof(T), "Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined");
                          ^~~~~~~~~
    

    It just doesn't make sense in term of design to include the Controller in a the header of a simple Model... don't you agree?
    And it would give me circular inclusion as in my Controller I include some models to be able to use inline methods on them...
    I guess I could remove my inline methods but still I'm not really happy with including a main object in a Model definition.

    What could I do? holding a QObject instead and use static_cast in the cpp? doesn't look so nice...

    Why this static_assert as been added?!?

    PS: there is this thread on stackoverflow for this problem but without a proper solution

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      It is explained in this blog post: https://www.qt.io/blog/whats-new-in-qmetatype-qvariant
      The 2 solutions you can implement are:

      • use Q_MOC_INCLUDE("ClementineRemote.h") to let moc know of the type without actually needing to include it
      • use Q_DECLARE_OPAQUE_POINTER to let moc know you actually want to use a non-fully-defined type

      "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
      4
      • mbruelM Offline
        mbruelM Offline
        mbruel
        wrote on last edited by
        #3

        @VRonin cool thanks, I didn't find that post...
        It works perfectly with Q_MOC_INCLUDE("ClementineRemote.h") but I don't understand how to use Q_DECLARE_OPAQUE_POINTER :$...
        Any help?
        I've just added it like that:

        #ifndef REMOTEFILEMODEL_H
        #define REMOTEFILEMODEL_H
        #include <QAbstractListModel>
        
        class ClementineRemote;
        Q_DECLARE_OPAQUE_POINTER(ClementineRemote)
        
        class RemoteFileModel : public QAbstractListModel
        {
            Q_OBJECT
            Q_PROPERTY(ClementineRemote *remote READ remote WRITE setRemote)
        
        

        But I'm having the same crash.
        How am I supposed to use it?

        VRoninV 1 Reply Last reply
        0
        • mbruelM mbruel

          @VRonin cool thanks, I didn't find that post...
          It works perfectly with Q_MOC_INCLUDE("ClementineRemote.h") but I don't understand how to use Q_DECLARE_OPAQUE_POINTER :$...
          Any help?
          I've just added it like that:

          #ifndef REMOTEFILEMODEL_H
          #define REMOTEFILEMODEL_H
          #include <QAbstractListModel>
          
          class ClementineRemote;
          Q_DECLARE_OPAQUE_POINTER(ClementineRemote)
          
          class RemoteFileModel : public QAbstractListModel
          {
              Q_OBJECT
              Q_PROPERTY(ClementineRemote *remote READ remote WRITE setRemote)
          
          

          But I'm having the same crash.
          How am I supposed to use it?

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

          You were almost there! Q_DECLARE_OPAQUE_POINTER wants the pointer type, not the underlying type: Q_DECLARE_OPAQUE_POINTER(ClementineRemote*)

          "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
          2
          • mbruelM Offline
            mbruelM Offline
            mbruel
            wrote on last edited by
            #5

            @VRonin my bad.. thanks!
            as it can't be redefined, it's kind of needed to use macros:

            #ifndef REMOTEFILEMODEL_H
            #define REMOTEFILEMODEL_H
            #include <QAbstractListModel>
            
            class ClementineRemote;
            #ifndef OPAQUE_ClementineRemote
            #define OPAQUE_ClementineRemote
            // To avoid Qt6 error: Type argument of Q_PROPERTY must be fully defined
            // cf https://www.qt.io/blog/whats-new-in-qmetatype-qvariant
            //Q_MOC_INCLUDE("ClementineRemote.h")
            Q_DECLARE_OPAQUE_POINTER(ClementineRemote*)
            #endif // OPAQUE_ClementineRemote
            
            
            class RemoteFileModel : public QAbstractListModel
            {
                Q_OBJECT
                Q_PROPERTY(ClementineRemote *remote READ remote WRITE setRemote)
            
            VRoninV 1 Reply Last reply
            2
            • mbruelM mbruel

              @VRonin my bad.. thanks!
              as it can't be redefined, it's kind of needed to use macros:

              #ifndef REMOTEFILEMODEL_H
              #define REMOTEFILEMODEL_H
              #include <QAbstractListModel>
              
              class ClementineRemote;
              #ifndef OPAQUE_ClementineRemote
              #define OPAQUE_ClementineRemote
              // To avoid Qt6 error: Type argument of Q_PROPERTY must be fully defined
              // cf https://www.qt.io/blog/whats-new-in-qmetatype-qvariant
              //Q_MOC_INCLUDE("ClementineRemote.h")
              Q_DECLARE_OPAQUE_POINTER(ClementineRemote*)
              #endif // OPAQUE_ClementineRemote
              
              
              class RemoteFileModel : public QAbstractListModel
              {
                  Q_OBJECT
                  Q_PROPERTY(ClementineRemote *remote READ remote WRITE setRemote)
              
              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @mbruel said in Qt6 regression with QAbstractListModel? Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined:

              as it can't be redefined, it's kind of needed to use macros:

              I would have thought the include guard on the header already took care of this but I might be wrong

              "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

              mbruelM 1 Reply Last reply
              0
              • VRoninV VRonin

                @mbruel said in Qt6 regression with QAbstractListModel? Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined:

                as it can't be redefined, it's kind of needed to use macros:

                I would have thought the include guard on the header already took care of this but I might be wrong

                mbruelM Offline
                mbruelM Offline
                mbruel
                wrote on last edited by
                #7

                @VRonin said in Qt6 regression with QAbstractListModel? Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined:

                I would have thought the include guard on the header already took care of this but I might be wrong

                No it's not cause I've several Models using it. They all need it for their moc compilation. But then their headers are included in the main object ClementineRemote that is where there is the redefinition.

                1 Reply Last reply
                2

                • Login

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