[Interest] Porting custom QML plugin to the Qt6

Ulf Hermann ulf.hermann at qt.io
Wed Apr 28 22:33:42 CEST 2021


Hi Jakub,

nice to hear someone is trying the fancy new QML type registration!

> [...]
> I spotted, I believe, the most important changes. QQmlExtensionPlugin 
> being changed to QmlEngineExtensionPlugin, QML_ELEMENT added in Qt 
> 5.15.X and removal of QQmlExtensionPlugin::registerTypes.

Technically, QQmlExtensionPlugin with its cruft is still there, but 
indeed you shouldn't use it. The new CMake API will default to 
auto-generating a minimal optional plugin. The actual meat of the QML 
types will then be in a backing library that you can directly link into 
your application. This way it won't have to load the plugin at all.

> Then I noticed stuff about QML_IMPORT_NAME, QML_IMPORT_MAJOR_VERSION and 
> 'CONFIG += qmltypes' that are supposed to be added to the .pro project 
> files. And, although, docs are silent about CMake, there is handy 
> example located at:
> https://code.qt.io/cgit/qt/qtdeclarative.git/tree/examples/qml/qmlextensionplugins/CMakeLists.txt?h=6.0 

Well, yes, the CMake API is in tech preview right now, and it will 
change quite a bit.

> [...] > omitting, for the moment, the "QT_QMLTYPES_FILENAME
> imports/TimeExample/plugins.qmltypes" as I was typically generating 
> .qmltypes manually using the supplied qmlplugindump and some associated 
> CMake hackery.

Don't do this. qmlplugindump is deprecated. qmltyperegistrar can 
generate better qmltypes files.

> [...]
> 
> But! My includes are not available under <SomeBeautifulHeader.h> but 
> rather under "IzLibrary/SomeBeautifulHeader.h" as denoted by my 
> target_include_directories:
> 
> # include directories for target
> target_include_directories(
>      IzLibraryPlugin
> PUBLIC
>      $<INSTALL_INTERFACE:include>
>      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
> PRIVATE
>      ${CMAKE_CURRENT_SOURCE_DIR}/private
> )
> 
> So, my questions (for now :P) are:
> Is this the intended behavior or have I fubared something and not added 
> "something, somewhere" in my CMakeLists.txt?

This is expected. You need to make the headers for your QML-exposed 
types available in the include paths for the generated code to find it. 
An -IIzLibrary should fix this. Anything else would be a series of never 
ending headaches, considering the different paths of your sources and 
generated files in source, build, and install directories. Also, the 
metatype information is generated by moc and moc doesn't know where your 
"reference" path should be.

> Is there a documentation for the qt6_* cmake functions?

Not yet. The CMake API is being redesigned right now. Don't expect 
anything to stay the same.

> Is the stuff "qt6_add_qml_module" important or can I skip it?

That will indeed be the way to add QML modules. However, what you 
currently see there is not very useful.

cheers,
Ulf


More information about the Interest mailing list