Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
6.6.0 Beta2
-
None
-
Qt 6.6, QMake (the first step porting my 20 mobile business Apps from 5.15.14 I'm using QMake. when all is working I'll move to CMake)
Description
Having huge problems porting mobile business Apps (Android, iOS) using C++ Forward Declarations from 5.15 to 6.6
In my Entity / DTO - data models there are dependencies between QObject* classes in both directions. To avoid cyclic references while importing C++ header, C++ Forward Declaration is used.
This works well in Qt 5.15, but fails in 6.6 with errors like:
Error Pointer Meta Types...must be declared with Q_DECLARE_OPAQUE_POINTER In file included from moc_MixArticle.cpp:9: In file included from ./../../_qt_ws6/thielen_eingang_Qt6/cpp/gen/MixArticle.hpp:4: In file included from ../../_qt_sdks/sdk_6_6b2/6.6.0/android_arm64_v8a/include/QtCore/QObject:1: In file included from ../../_qt_sdks/sdk_6_6b2/6.6.0/android_arm64_v8a/include/QtCore/qobject.h:18: ../../_qt_sdks/sdk_6_6b2/6.6.0/android_arm64_v8a/include/QtCore/qmetatype.h:1189:13: error: static_assert failed due to requirement 'is_complete<OrderItem, void>::value' "Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *)" static_assert(is_complete<Pointed, void>::value, ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So I added the recommended Q_DECLARE_OPAQUE_POINTER:
#include <QMetaObject> ... class OrderItem; #ifndef OPAQUE_OrderItem #define OPAQUE_OrderItem Q_DECLARE_OPAQUE_POINTER(OrderItem*) #endif ... class MixArticle: public QObject { ...
see attached file
Yep, in this scenario it is working after adding Q_DECLARE_OPAQUE_POINTER, but not in all scenarios,
Found out, that it always works for bi-directional references using ForwardDeclaration only at one of the sides as in the example above, where only MixArticle forward-declares OrderItem, but OrderItem includes MixArticle header.
When ForwardDeclarations are used on both sides I'm getting errors.
Then something like this occurred:
error: explicit specialization of 'QtPrivate::IsPointerDeclaredOpaque<MyQObject *>' after instantiation Q_DECLARE_OPAQUE_POINTER(MyQObject*)
Workaround: In my Apps I removed the forward-declaration from one side of all bi-directional references.
This works for most of my 20 mobile business Apps being ported from 5.15 to 6.6
Unfortunately now in very less scenarios C++ now gives me errors like
In included file: main file cannot be included recursively when building a preamble Serie.hpp:14:10: error occurred here
Nothing complained by Q_DECLARE_OPAQUE_POINTER.
In 5.15 all worked well with forward-declarations on both sides.
The only workaround for now to be able to go on porting my apps: I had to decouple some references to make it compile again. Of course I'm not happy with this: changing my data model and changing C++ and QML code. Have described one of the special cases here at my blog.