The doc shows I can use QML_ELEMENT macro to create QML types from C++ by adding some variables in qmake's .pro file. But I'm using cmake
As of Qt 6.2, qt_add_qml_module is a single command for building qml modules that should take care of virtually everything, replacing amongst others the old qt6_qml_type_registration
command.
Now that Qt 6.0 is out this is supported, albeit poorly documented. What you need now is:
set_target_properties(foo PROPERTIES
QT_QML_MODULE_VERSION 1.0
QT_QML_MODULE_URI Foo
)
qt6_qml_type_registration(foo)
you can then do in qml:
import Foo
and you'll have access to types that have QML_ELEMENT
and friends. Notes:
<project>_qmltyperegistrations.cpp
and <project>.qmltypes
, if your imports are failing you can look at those to see which types are missing. I found that I needed to do full recompiles sometimes after adding/removing registered types.Examples/Qt-6.0.0/quick/tableview/gameoflife
to see it in actionpro2cmake.py
and run_pro2cmake.py
files in the Qt sources at Qt/6.0.0/Src/qtbase/util/cmake
. They are mentioned on this Readme page, you can find them here, haven't tried it myself.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With