[Interest] Refusing to generate non-lowercase name "A" for unknown foreign type
Stefan Seefeld
stefan at seefeld.name
Thu Aug 15 16:31:03 CEST 2024
Hello,
I figured out a partial answer myself, which I'm sharing here in the hopes
that someone else might find it useful as well.
It turns out that the use of `QML_FOREIGN` requires meta-information of the
foreign types to be present. In the case
of this simplistic test case here, this can be achieved by calling
`qt_extract_metatypes(A)` next to where `qt_add_qml_module(B ...)`
is called.
Unfortunately this is not enough in my real case, where `A` is not only a
different library, but is provided by a separate (debian) package,
so `A` in the current project is an INTERFACE target, which
`qt_extract_metatypes()` falls over with an obscure error.
On Wed, Aug 14, 2024 at 1:49 PM Stefan Seefeld <stefan at seefeld.name> wrote:
> I'm still trying to generate an QML module from some legacy code.
> Consider this layout:
>
> .
> ├── A
> │ ├── A.cpp
> │ ├── A.h
> │ └── CMakeLists.txt
> ├── B
> │ ├── B.cpp
> │ ├── B.h
> │ ├── CMakeLists.txt
> │ ├── QML.cpp
> │ └── QML.h
> └── CMakeLists.txt
>
> Subdirectory `A/` generates a DSO `libA.so` containing class `A` (derived
> from `QObject`).
> Subdirectory `B/` generates a DSO `libB.so` containing class `B` (derived
> from `QObject`).
> Subdirectory `B/` also defines a QML module `B` that should expose `A` and
> `B`.
> The file `B/QML.h` thus contains
>
> ```
> #include "../A/A.h"
> #include "B.h"
> #include <QQmlEngine>
>
> struct AProxy
> {
> Q_GADGET
> QML_FOREIGN(A)
> QML_UNCREATABLE("")
> QML_NAMED_ELEMENT(A)
> };
>
> struct BProxy
> {
> Q_GADGET
> QML_FOREIGN(B)
> QML_UNCREATABLE("")
> QML_NAMED_ELEMENT(B)
> };
> ```
> The makefile then uses `qt_add_qml_module` to compile the above. This
> results in the message
>
> Warning: Refusing to generate non-lowercase name "A" for unknown foreign
> type
>
> and indeed, the generated `B/B.qmltypes` contains
>
> ...
> // This file was auto-generated by qmltyperegistrar.
>
> Module {
> Component { file: "QML.h"; name: "A"; accessSemantics: "none" }
> Component {
> file: "QML.h"
> name: "B"
> accessSemantics: "reference"
> prototype: "QObject"
> exports: ["B/B 1.0"]
> isCreatable: false
> exportMetaObjectRevisions: [256]
> }
> }
>
> Why is foreign type `A` "unknown", and the type generation thus (almost)
> empty ?
>
> Previously we were using Qt5, where we would use explicit calls to
> `qmlRegister...Type` to expose C++ types to QML. As I'm now trying to
> modernize all that code following (
> https://doc.qt.io/qt-6/qt-add-qml-module.html), I'm stumbling over a
> couple of important roadblocks.
> Any help is much appreciated !
>
> Thanks,
>
> --
>
> ...ich hab' noch einen Koffer in Berlin...
>
>
--
...ich hab' noch einen Koffer in Berlin...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240815/a3f7cb26/attachment.htm>
More information about the Interest
mailing list