Silex
Silex

Reputation: 2713

Custom QML module not found

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?

Upvotes: 3

Views: 7960

Answers (1)

Silex
Silex

Reputation: 2713

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.

Upvotes: 5

Related Questions