[Interest] problem with type registration during QML module compilation

Mike Trahearn miketrahearn at imagineuisoftware.com
Sat Jul 13 04:06:52 CEST 2024


Hello Stefan,

I was certain I could help you so I recreated your scenario - and found the same problem.

I tried many different ways of coaxing the include path to be visible to the type registration system - all in vain.
So I started digging around in code reviews, docs, forums and the like. Turns out this is not a new problem - but it is still a problem that isn’t going to get fixed...

https://stackoverflow.com/questions/74854202/qmltyperegistration-include-path-does-not-acknowledge-subdirectories

… because you will sadly find that Qt have designed it this way and there is no other way round it other than to ensure all your qt_add_qml_module SOURCES are in the same folder as the QML Module’s CMakeLists.txt file.
The same actually applies to QML files as well.

A somewhat cryptic note in the documentation was added:

https://doc.qt.io/qt-6/qtqml-cppintegration-definetypes.html

"NOTE: All headers that declare QML types need to be accessible without any prefix from the project's include path."

I sincerely wanted to send you back a zip of the solution for you but it does rather appear that your refactoring is going to take sorry turn to get it working as your existing include paths from the non QML Module-ised project are going to break as you do so.

QML Modules - brilliant if they work. PITA when they don’t. And such wonderful documentation for mere mortals.

Mike

> On 13 Jul 2024, at 4:36 AM, Stefan Seefeld <stefan at seefeld.name> wrote:
> 
> Hello,
> 
> any idea why I'm getting the below error ? What tool is used to generate the *_qmltyperegistrations.cpp file, and how does it figure out to add the line `#include <A.h>` instead of `#include <view/A.h>` ?
> 
> On Fri, Jul 5, 2024 at 10:15 AM Stefan Seefeld <stefan at seefeld.name <mailto:stefan at seefeld.name>> wrote:
>> Hello,
>> 
>> following up on an earlier conversation...
>> 
>> I'm trying to convert a legacy QML module to use the "new" `qt_add_qml_module` function. This process includes the generation of a ..._qmltyperegistrations.cpp file that contains an invalid reference to a header file <A.h>
>> 
>> My library layout looks like this:
>> 
>> libs/foo/
>> ├── CMakeLists.txt
>> ├── view
>> │   ├── A.h
>> │   ...
>> ├── qml
>> ...
>> 
>> and the makefile above compiles a shared library libfoo.so from the contents. I now want to use `qt_add_qml_module()` to automate the generation of the associated QML module (including all the QML resources, as well as exposing the QML types defined in C++, such as the one in `view/A.h`. However, the generated code expects to be able to include "A.h", while it should actually be including "view/A.h". Is there a property I should be passing to `qt_add_qml_module()` to make that happen, or is there anything else I'm missing ?
>> 
>> For context: The type `A` is actually a singleton (a QQmlPropertyMap) which is accessed directly from C++ code, so its C++ API needs to be accessible as a regular class in the library, in addition to being registered to the QML runtime.
>> 
>> Thanks for any help,
>> 
>> -- 
>> 
>>       ...ich hab' noch einen Koffer in Berlin...
> 
> 
> -- 
> 
>       ...ich hab' noch einen Koffer in Berlin...
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org <mailto:Interest at qt-project.org>
> https://lists.qt-project.org/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240713/f8e74ea5/attachment.htm>


More information about the Interest mailing list