Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-107525

Using a c++ QML component within its own QML module requires the module to import itself

    XMLWordPrintable

Details

    • All

    Description

      I am creating a QML module "MyModule" using the cmake command qt_add_qml_module().

      The module contains a native component UtilsNative.hpp/cpp exposed to QML using QML_ELEMENT and a regular QML component Utils.qml.

      If I want to use the UtilsNative QML component inside Utils.qml I need the later to contain the line "import MyModule" otherwise the native type is unkown. This doesn't really makes sense since both are already inside the MyModule module. I would expect that all native components added to a module with qt_add_qml_module() are also automatically visible to all other qml components from the same module. It is the case for regular qml components in the same module, but not for native ones.

       

      This behavior is getting really annoying when a QML module also contains Singletons deriving from native components, because it ends up creating artificial cyclic dependencies.

      I attach a test project showing the issue. Running this project ends up with an error message "Cyclic dependency detected between "qrc:/MyModule/Utils1.qml" and "qrc:/MyModule/Utils2.qml"" although the dependency really isn't cyclic.

       

      A workaround is to move all native QML components in its own QML module but this make the project over-complicated.

      Attachments

        Activity

          People

            qtqmlteam Qt Qml Team User
            xalioth Fabien Chéreau
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: