[Interest] using a C++ class in QML in Qt6

Dirk Hohndel dirk at hohndel.org
Sat Aug 31 21:23:33 CEST 2024


Hi there,

I've been trying to figure out how to port a QML app from Qt5 to Qt6 and have been unable to solve what seems like a fairly basic issue.

In the Qt5 version, I was able to make a class available from C++ by simply calling

...
qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile)
...

in the C++ code and then using

import org.subsurfacedivelog.mobile

in the QML file in order to then be able to use that type as

QMLProfile {
...
}

in the QML code.

When I try this code unmodified, it compiles fine, but at run time tells me that it cannot find the org.subsurfacedivelog.mobile module when it encounters that import org.subsurfacedivelog.mobile line.

So I tried some searching and found several pages in the Qt6 documentation that all seem to imply that this isn't how things should be done in Qt6 and that instead I would need to go down the route of defining a separate QML module with its own compile unit (is this true? why would you disable this core feature???)

And then trying to do that, I fail to get the module to compile with missing include paths.
If it turns out that that's the only way to go, I'll happily give a lot more details on this issue -- but I'd love to first get back to the previous approach.
Is there still a way in Qt6 to register a Type with QML without having to create separate modules?

Thanks

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


More information about the Interest mailing list