Re: [Interest] Porting custom QML plugin to the Qt6
See also https://bugreports.qt.io/browse/QTBUG-89274 and some of the related tasks. > -Original Message- > From: Interest On Behalf Of Jakub > Narolewski > Sent: Wednesday, 28 April 2021 9:54 PM > To: interest@qt-project.org > Subject: [Interest] Porting custom QML plugin to the Qt6 > > Lately, mostly for fame and glory, I decided to port some of my stuff from > Qt5 to Qt6. > Most of it went ok'ish - after some CMakeLists.txt hacking and 'modernizing' > the code I was able to compile two of my dynamic libraries under Qt6. > > Problems started with my custom QML plugin. Here after compiling and > importing my module in my example app I got: > "qrc:/src/QML/MainWindow.qml:5:1: module "IzLibrary" plugin > "IzLibraryPlugin" not found" > > Well oopsie doopsie, some more work is needed. After quick look at: > https://doc.qt.io/qt-6/qtqml-modules-cppplugins.html > > 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. > > 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/qmlextensio > nplugins/CMakeLists.txt?h=6.0 > > I added to my CMakeLists.txt: > > set_target_properties( > IzLibraryPlugin > PROPERTIES > QT_QML_MODULE_VERSION 1.0 > QT_QML_MODULE_URI IzLibrary > ) > > 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. > > I also added the: > > qt6_qml_type_registration(IzLibraryPlugin) > > And this is when first build error occurred. qt6_qml_type_registration seems > to be trying to automate some of the QML type registration machinery and > generates the "izlibraryplugin_qmltyperegistrations.cpp" file. In my case it > looks like this: > > #include > #include > > #include > #include > #include > > void qml_register_types_IzLibrary() > { > qmlRegisterTypesAndRevisions("IzLibrary", > 1); > qmlRegisterTypesAndRevisions("IzLibrary", > 1); > qmlRegisterTypesAndRevisions("IzLibrary", 1); > QMetaType::fromType().id(); > QMetaType::fromType().id(); > qmlRegisterModule("IzLibrary", 1, 0); } > > static const QQmlModuleRegistration registration("IzLibrary", > qml_register_types_IzLibrary); > > > But! My includes are not available under but > rather under "IzLibrary/SomeBeautifulHeader.h" as denoted by my > target_include_directories: > > # include directories for target > target_include_directories( > IzLibraryPlugin > PUBLIC > $ > $ > 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? > Is there a documentation for the qt6_* cmake functions? > Is the stuff "qt6_add_qml_module" important or can I skip it? > ___ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] Porting custom QML plugin to the Qt6
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 but rather under "IzLibrary/SomeBeautifulHeader.h" as denoted by my target_include_directories: # include directories for target target_include_directories( IzLibraryPlugin PUBLIC $ $ 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 ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
[Interest] Porting custom QML plugin to the Qt6
Lately, mostly for fame and glory, I decided to port some of my stuff from Qt5 to Qt6. Most of it went ok'ish - after some CMakeLists.txt hacking and 'modernizing' the code I was able to compile two of my dynamic libraries under Qt6. Problems started with my custom QML plugin. Here after compiling and importing my module in my example app I got: "qrc:/src/QML/MainWindow.qml:5:1: module "IzLibrary" plugin "IzLibraryPlugin" not found" Well oopsie doopsie, some more work is needed. After quick look at: https://doc.qt.io/qt-6/qtqml-modules-cppplugins.html 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. 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 I added to my CMakeLists.txt: set_target_properties( IzLibraryPlugin PROPERTIES QT_QML_MODULE_VERSION 1.0 QT_QML_MODULE_URI IzLibrary ) 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. I also added the: qt6_qml_type_registration(IzLibraryPlugin) And this is when first build error occurred. qt6_qml_type_registration seems to be trying to automate some of the QML type registration machinery and generates the "izlibraryplugin_qmltyperegistrations.cpp" file. In my case it looks like this: #include #include #include #include #include void qml_register_types_IzLibrary() { qmlRegisterTypesAndRevisions("IzLibrary", 1); qmlRegisterTypesAndRevisions("IzLibrary", 1); qmlRegisterTypesAndRevisions("IzLibrary", 1); QMetaType::fromType().id(); QMetaType::fromType().id(); qmlRegisterModule("IzLibrary", 1, 0); } static const QQmlModuleRegistration registration("IzLibrary", qml_register_types_IzLibrary); But! My includes are not available under but rather under "IzLibrary/SomeBeautifulHeader.h" as denoted by my target_include_directories: # include directories for target target_include_directories( IzLibraryPlugin PUBLIC $ $ 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? Is there a documentation for the qt6_* cmake functions? Is the stuff "qt6_add_qml_module" important or can I skip it? ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest