我正在努力使用自定义 QML 模块。奇怪的是,当我在 Linux (Ubuntu) 上构建和运行时它工作得很好,但是当我在 Windows 上构建和运行时,我收到以下运行时错误
Module jbQuick.Charts is not installed.
我的根项目目录包含一个文件夹qml/jbQuick/Charts
,其中包含qmldir
和QML文件。在.pro
文件中添加QML目录:
QML_IMPORT_PATH = qml
在main.cpp文件中添加qml目录:
QQmlApplicationEngine engine;
engine.addImportPath(QStringLiteral("jbQuick/Charts"));
engine.addImportPath(QStringLiteral("qml"));
在我想使用自定义模块的 QML 文件中,我声明:
import jbQuick.Charts 1.0
我错过了什么吗?这是一个已知的问题?
最佳答案
最可能的原因是相对路径在 Windows 系统上的解释不同 - 可能是因为运行程序时的当前目录不是项目根目录。您可以尝试绝对路径,即:
engine.addImportPath("<your-project-root>/qml");
如果有效,您可以使用 GetModuleFileName 在运行时创建相对于二进制文件的正确路径。
关于linux - QtQuick : Module is not installed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33548118/