Equivalent of CONFIG+=qmltypes in CMake build?



  • Hello.
    I just found out about the new way to expose C++ types to QML using the
    QML_ELEMENT macro, as described e.g. here.

    To test it with CMake builds, I converted the Adding example
    Qt/Examples/Qt-5.15.0/qml/referenceexamples/adding
    to a CMake project.

    While it runs fine when using the old way of registering the type with

    qmlRegisterType<Person>("People", 1,0, "Person");
    

    it fails when commenting that line out (and uncommenting the QML_ELEMENT macro):

    QQmlComponent: Component is not ready
    (qrc:example.qml:52:1: module "People" is not installed
        import People 1.0
        ^)
    

    I assume it has to do with not having used the CMake equivalent of the following .pro line:

    CONFIG+=qmltypes
    

    But, what is the CMake equivalent of the above CONFIG flag?

    Thanks for your help!



  • @gillamkid, @Seboo
    It seems CONFIG+=qmltypes is not supported in CMake for Qt 5 versions, but can be used in Qt 6, as described here:
    https://stackoverflow.com/questions/63509161/how-to-use-qml-element-with-cmake

    Have not tested it though.


Log in to reply