问题描述
我需要为项目提供一些模块.
现在,它会在QT目录中查找它们(我已将它安装在 $ HOME
中),但我想让它在/usr/lib/x86_64中进行搜索-linux-gnu/qt5/qml/
.
Now, it looks for them in QT directory(I've installed it in $HOME
), but instead of it I want to make it search in /usr/lib/x86_64-linux-gnu/qt5/qml/
.
我尝试过的事情:
a)在 .bashrc
中定义 QML_IMPORT_PATH
-无法解决
What I have tried:
a) Defining QML_IMPORT_PATH
in .bashrc
- didn't work out
b)在 $ HOME/Qt5.5.1/Tools/QtCreator/bin/qml/
中复制所需的模块:
b) Copying needed module in $HOME/Qt5.5.1/Tools/QtCreator/bin/qml/
:
在这里,我们有一些不同之处.如果打开 .qml
文件-它不会在 import
行下划线(可以).但是,如果我使用控制台运行可执行文件-相同的消息模块org.bla.bla未安装
.
Here we have something different. If I open of the .qml
files - it wouldn't underscore import
line (which is ok). But, If I run executable with console - the same message module org.bla.bla is not installed
.
因此,如果复制无济于事,也许我只能让QtCreator(或其他)在适当的文件夹中搜索模块,但是如何?
So, If copying didn't help, maybe I had to just make QtCreator(or smth else) search for modules in appropriate folder, but how?
UPD.
好了,您可以使用 QML2_IMPORT_PATH
(不仅是 QML
,而且是 QML2
)定义模块的路径.如上所述,我已经将模块文件夹复制到 $ HOME/Qt5.5.1/Tools/QtCreator/bin/qml/
中,这是完全错误的!正确的方法是将其复制到 $ QT_HOME/5.5/gcc_64/qml/
中.它现在可以正常运行,但是我不能对它的运行方式"说同样的话.不幸的是,这与我提出的问题无关.因此,我不会要求其他人回答我的问题,但是直到找到真正的问题并在此处提及它时,我才会将其关闭,以便为他人提供帮助.
UPD.
Well, you can define path to your modules with QML2_IMPORT_PATH
(not just QML
, but QML2
). As I mentioned above, I've copied module folder in $HOME/Qt5.5.1/Tools/QtCreator/bin/qml/
which is completely wrong! The right way was to copy it in $QT_HOME/5.5/gcc_64/qml/
. It runs now fine, but I can't say the same about "how" it works. Unfortunately, this is not related to the question I've asked. Therefore, I'll not ask others to answer my question, but won't close it as well until find real problem and mention it here, so I can help others.
推荐答案
有了新的和即将发布的QtCreator 4.1,您将能够做到这一点.只需在CMake缓存中设置 QML_IMPORT_PATH
即可.如果您有多个路径,请使用;
分隔它们,这就是在CMake中完成列表的方式.
With the new and upcoming QtCreator 4.1 you will be able to do that. Just set QML_IMPORT_PATH
in your CMake cache. If you have multiple paths, separate them with a ;
which is just how a list is done 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")
这篇关于如何在Qt Cmake项目中使用QML_IMPORT_PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!