How to use QML_IMPORT_PATH with a Qt Cmake project?

I need to provide some modules for the project.

Now he searches for them in the QT directory (I installed it in $HOME ), but instead I want to search in /usr/lib/x86_64-linux-gnu/qt5/qml/ .

What I tried:
a) QML_IMPORT_PATH definition in .bashrc - did not work

b) Copy the required module to $HOME/Qt5.5.1/Tools/QtCreator/bin/qml/ :

Here we have something else. If I open .qml files, this will not underline the import line (this is normal). But, if I run the executable file with the console - the same message module org.bla.bla is not installed .

So, if copying didn't help, maybe I just had to do a QtCreator (or smth else) search for the modules in the appropriate folder, but how?

UPD
Well, you can determine the path to your modules using QML2_IMPORT_PATH (not just QML , but QML2 ). As I mentioned above, I copied the module folder to $HOME/Qt5.5.1/Tools/QtCreator/bin/qml/ , which is completely wrong! The correct way is to copy it to $QT_HOME/5.5/gcc_64/qml/ . It works fine, but I can't say the same about how it works. Unfortunately, this is not related to the question I asked. Therefore, I will not ask others to answer my question, but I will not close it until I find the real problem and mention it here, so I can help others.

+5
source share
1 answer

With the new and upcoming QtCreator 4.1 you can do it. Just set QML_IMPORT_PATH to your CMake cache. If you have multiple paths, divide them by ; which is how the list is executed in CMake.

 list(APPEND QML_DIRS "dir1") list(APPEND QML_DIRS "dir2") set(QML_IMPORT_PATH "${QML_DIRS}" CACHE STRING "Qt Creator 4.1 extra qml import paths") 
+4
source

Source: https://habr.com/ru/post/1238704/


All Articles