2

I have a QML application. I have created my own QML module. called MyCustomModule. The module has the appropriate qmldir file, which is registered to the corresponding my_custom_module.qrc file. I also add the import path with addImportPath("qrc:///my_custom_module"); on application startup in C++. I am using CMake instead of QMake.

Where ever I import MyCustomModule QtCreator tells me QML module not found, but when I build the application builds without any issues and runs.

Am I missing something?

Silex
  • 2,583
  • 3
  • 35
  • 59
  • You better should provide some source code instead of explaining it. – folibis May 30 '19 at 08:26
  • 1
    I think in this case source code would have been just a dead end and would have just deflect the attention from the real issue. As I said the code is fine since it builds and runs. On the other hand I have found the solution adding it as an answer. – Silex May 30 '19 at 14:47

1 Answers1

5

My issue was that I was missing QML_IMPORT_PATH from my CMake file. Example:

# Make Qt Creator aware of where the QML modules live
set (_QML_IMPORT_PATHS "")

## Add new module paths here.
list (APPEND _QML_IMPORT_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/path/to/your/module)

set (
    QML_IMPORT_PATH
    ${_QML_IMPORT_PATHS}
    CACHE
    STRING
    "Path used to locate CMake modules by Qt Creator"
    FORCE
)

One important side note is that the ${CMAKE_CURRENT_SOURCE_DIR}/path/to/your/module should point to the folder where the module lives and not to the module folder itself. So if you have a path like this: /path/to/your/module/MyCustomModule, the CMake should contain the path /path/to/your/module.

Silex
  • 2,583
  • 3
  • 35
  • 59
  • For an improved way to set `QML_IMPORT_PATH` in the CMake makefile, [see here](https://stackoverflow.com/a/38266179). – tanius Jun 04 '20 at 19:11