[Interest] Refusing to generate non-lowercase name "A" for unknown foreign type

Stefan Seefeld stefan at seefeld.name
Wed Aug 14 19:49:52 CEST 2024


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...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240814/72bd4f16/attachment.htm>


More information about the Interest mailing list