未找到 QML 模块错误 [英] QML module not found error
问题描述
使用 QtCreator 时,我在编辑器中显示一个 qml 文件.qml 文件用于名为 main.qml
的文件,它是一个插件.
When using QtCreator, I display a qml file in the editor. The qml file is for a file named main.qml
that is a plugin.
然后我点击Design
按钮.它显示错误消息:QML module not found
.
I then click on the Design
button. It displays the error message: QML module not found
.
如果我使用 Go to error
链接,它会转到包含以下 import com.name.os.app.all 1.0
的行.这是插件需要的各种组件qml文件的位置.
If I take the Go to error
link it goes to a line containing the following import com.name.os.app.all 1.0
. This is the location of various component qml files needed by the plugin.
我已将路径 c:\users\me\ui\viewer\
添加到我的 QML_IMPORT_PATH
env
变量中.如果 QtCreater 将 qml 文件导入语句中的 com.name...
附加到我添加到 QML_IMPORT_PATH
的路径名,它会找到所需的目录.没有.
I have added the path c:\users\me\ui\viewer\
to my QML_IMPORT_PATH
env
variable. If QtCreater appends the com.name...
from the qml file import statement to the pathname I added to QML_IMPORT_PATH
, it would find the desired directory. It doesn't.
项目使用 qmake.
The project uses qmake.
我尝试使用 qmlplugindump.exe
为我的主 qml 视图容器文件生成 qmltypes
文件,但是 qmlplugindump.exe
给了我错误提示 component is not ready
和 file::///c:/Users/name/ui/viewer/modules/app/qml/com/name/os/app/all/typelist.qml:2:1 模块 MyViewContainer.qml 未安装
.
I have tried using qmlplugindump.exe
to generate a qmltypes
file for my main qml view container file, but qmlplugindump.exe
gives me an error saying the component is not ready
and file::///c:/Users/name/ui/viewer/modules/app/qml/com/name/os/app/all/typelist.qml:2:1 module MyViewContainer.qml is not installed
.
我使用的命令是 qmlplugindump.exe MyViewContainer.qml 1.0 c:\users\myname\ui\viewer\modules\app\qml\com\name\os\app\all\ >...
推荐答案
这个错误毁了我的生活
QML 模块未找到错误"的真实解决方案:
假设你在这样的目录中有插件,里面有 qmldir"myproject/modules/mymodule/blabla.qmldir"
您需要在.pro"文件中导入这样的父目录:
This Error Ruined My Life
Real Solution for "QML module not found error":
lets say if you have plugins in directory like this, with qmldir inside it
"myproject/modules/mymodule/blabla.qmldir"
you need to import parent directory like this in ".pro" file :
QML_IMPORT_PATH += $$PWD/modules
不是这样的(这个不行):QML_IMPORT_PATH += $$PWD/modules/mymodule
//---------------------------------------------
旁注:
这也会发生在 qml 的其他部分,比如 qmlplugindump 你需要给父目录而不是确切的文件夹!但是 windeployqt 正在使用确切的文件夹
not like this (this one wont work):
QML_IMPORT_PATH += $$PWD/modules/mymodule
//---------------------------------------------
side note:
this is going to happen in other part of qml too like qmlplugindump you need to give parent directory not exact folder!
but windeployqt is working with exact folder
例如:
qmlplugindump lib 1.0 C:\Users\Administrator\Documents\projectName\3rdparty > C:\Users\Administrator\Documents\projectName\3rdparty\lib\lib.qmltypes
//-----------------------------------------
第二个最重要的部分是QML仿真层
在 Qt Creator 中,转到 tools->option->Qt Quick->Qt Quick Designer
选择使用使用所选qt构建的Qml仿真层"
如果它已经被选中,请查看顶级构建路径"下的文本框
它应该引用 Qt 版本 bin 目录,该目录应该与插件 Qt 版本相同:
//---------------------------------------------
and second most important part is QML emulation layer
in Qt Creator go to tools->option->Qt Quick->Qt Quick Designer
select "Use Qml emulation layer that is built with the selected qt"
if its already selected look at textbox under that "Top level build path"
it should refer to Qt version bin directory which should be same as plugins Qt version :
..\5.12.1\msvc2017\bin
对我来说:(它应该与您用于套件和 blabla 的版本相同)
for me its :(it should be same version as you used for kits and blabla)
C:\QtN\5.12.1\msvc2017\bin
它不应该是这样的:
it should not be like this one :
C:\Users\Administrator\AppData\Roaming\QtProject\qtcreator\qmlpuppet
在插件中添加新项目后不要忘记部署(cmd 命令):
dont forget to deploy after adding new item in plugins(cmd command) :
windeployqt --qmldir C:\Users\Administrator\Documents\projectName C:\Users\Administrator\Documents\build-projectName-5_12-Debug\debug
和插件转储:
qmlplugindump lib 1.0 C:\Users\Administrator\Documents\projectName\3rdparty > C:\Users\Administrator\Documents\projectName\3rdparty\lib\lib.qmltypes
此后如果 QtCreator 为插件中的新对象出错,您需要重新启动 QtCreator,就是这样!
after this point if QtCreator gives error for new Objects in Plugins you need to restart QtCreator thats it!
如果仍然存在问题,您需要 - Clean All - Run Qmake - Rebuild all 解决了很多问题.在某些情况下,您需要将 qml 文件放入 5.13.1\msvc2017\qml
或任何适用于您的 qt 版本的文件
if still there is problems you need to - Clean All - Run Qmake - Rebuild all which solves so many issues.
and in some cases you need to put your qml files into 5.13.1\msvc2017\qml
or whatever is for your qt version
这篇关于未找到 QML 模块错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!