3

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?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

For an improved way to set QML_IMPORT_PATH in the CMake makefile, see here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.