-
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 appQObject
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
-
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
- use
-
@VRonin cool thanks, I didn't find that post...
It works perfectly withQ_MOC_INCLUDE("ClementineRemote.h")
but I don't understand how to useQ_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? -
@VRonin cool thanks, I didn't find that post...
It works perfectly withQ_MOC_INCLUDE("ClementineRemote.h")
but I don't understand how to useQ_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? -
@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)
-
@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)
@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
-
@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
@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.