[Development] Circular dependencies for Q_PROPERTY

Fabian Kosmale fabian.kosmale at qt.io
Mon Apr 27 12:11:03 CEST 2020


Hi,

the current solution in our repositories is to use the Q_MOC_INCLUDE(X) macro, which causes moc to write an #include X directive in the generated file. This avoids having to do the include in the header (which as you noticed isn't always possible).

We're aware of the issues, and there was some discussion around tooling, but I'm not aware of any outcomes so far.

Fabian

--
Fabian Kosmale
Software Engineer

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin
fabian.kosmale at qt.io
+49 1638686070
http://qt.io

Geschäftsführer: Mika Pälsi,
Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
--
________________________________
Von: Development <development-bounces at qt-project.org> im Auftrag von Mike Krus via Development <development at qt-project.org>
Gesendet: Montag, 27. April 2020 11:52
An: Qt Development Group <development at qt-project.org>
Betreff: [Development] Circular dependencies for Q_PROPERTY

Hi

I have 2 classes, A and B, derived from QObject, each have a property
of type pointer-to-other-class. So

class A : public QObject {
Q_PROPERTY(B *foo …)
…
};

And:

class B : public QObject {
Q_PROPERTY(A *foo …)
…
};

Because of the circular dependency, I can’t #include the full class
definition, just do forward declaration.

Now this fails in Qt 6, seems the moc generated code needs the
full class declaration.

Looking at generated moc code, looks like creating the meta object
requires a qt_metaTypeArray<A*, bool> which checks that A derives
from QObject by calling  IsPointerToTypeDerivedFromQObject
which uses sizeof() which requires the full type.

Any way around this? Seems like a rather big regression compared
to Qt 5…


Mike

—
Mike Krus | mike.krus at kdab.com | Senior Software Engineer
KDAB (UK) Ltd., a KDAB Group company
Tel: UK Office +44 1625 809908   Mobile +44 7833 491941
KDAB - The Qt Experts, C++, OpenGL Experts


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200427/bb1e5533/attachment.html>


More information about the Development mailing list