未安装 Qt5 QML 模块 [英] Qt5 QML module is not installed

查看:89
本文介绍了未安装 Qt5 QML 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Qt QML 中的模块感到困惑.我已经阅读了所有的文档,但它没有说明一些基本的想法.

I'm confused about modules in Qt QML. I've read all the docs, but it doesn't make clear some basic ideas.

我知道我可以将一堆 QML 文件放入一个目录并添加一个 qmldir 文件来描述已识别的模块.当我这样做并调整 QML_IMPORT_PATH 时,QtCreator 很高兴并停止在 import ModuleName 1.0 行下划线.

I understand that i can put a bunch of QML files into a directory and add a qmldir file to describe an identified module. When i do this and adjust the QML_IMPORT_PATH, QtCreator is happy and stops underlining the import ModuleName 1.0 line.

所以创作者很高兴,但它不起作用.我得到模块未安装.我的问题是:

So creator is happy, but it does not work. I get module is not installed. my questions are:

  • 已安装"是什么意思.我有文件目录,但我没有在任何地方安装"它们.
  • 我应该构建/编译模块以制作 DLL/.so 吗?
  • 模块 QML 文件是否进入主应用程序的资源,否则在哪里可以找到它们?
  • 我的 main.qml 文件是应用资源的一部分,应用在运行时如何定位模块的资源.

抱歉,对于所有这些问题,但这些模块的基础知识尚不清楚.我不明白一个模块"是只是共享文件还是编译单元.

Sorry, for all these questions, but the basics of these modules is just not clear. I don't understand if a "module" is just the sharing of files or is it a compiled unit.

感谢您的帮助.

推荐答案

我会尽力回答你的问题:

I'll try to answer your questions:

  • 我认为安装意味着它们位于正确的路径中,所以
    可以在运行时找到它们
  • 您不一定要为此目的创建/构建 QmlExtensionPlugin.您还可以将普通 QML 文件用作模块带有描述此模块的 qmldir 的目录.这是一个问题分发您的代码.使用 QmlExtensionPlugin 您提供模块编译,如果你想隐藏代码.
  • 模块可以在资源系统中或作为磁盘上的文件,这取决于您.
  • 应用程序在预定义路径中查找模块 - 在您的应用程序目录、Qt 插件路径、QML2_IMPORT_PATH、您使用 engine->addImportPath() 添加的目录中代码>
  • I think installed means they are located in the proper paths, so
    that they can be found at runtime
  • You should not necessarily create/build a QmlExtensionPlugin for that purpose. You can also use as a module plain QML files in one directory with a qmldir describing this module. It is a matter of distributing your code. With QmlExtensionPlugin you provide the module compiled, if you want to hide the code.
  • The modules can be in resources system or as files on disk, it is up to you.
  • The app looks for modules in predefined paths - in your app's directory, in Qt plugins path, in QML2_IMPORT_PATH, in directories that you added using engine->addImportPath()

有很多事情会导致模块没有被加载.您可以检查以下内容:

There are a bunch of things that can lead to a module not being loaded. You can check the following:

  1. qmldir 中的模块标识符应与目录相同名称,模块实际所在的位置.例如如果你的模块在 qmldir 中有模块标识符 module Test.Module,你的模块的相对路径必须是Test/Module.
  2. 如果是QML扩展插件(共享库),确保插件的目录名称是与插件名称相同.
  3. export QML2_IMPORT_PATH(确保名称中有 2)env 变量指向包含您的模块的目录.还有一个 QQmlEngine::addImportPath 方法,该方法将目录添加到列表中以查找插件.
  4. 如果它是一个qml扩展插件(共享库),那么它可能缺少依赖项.您可以通过 Windows 上的 Dependency Walker 或 Linux 上的 ldd 命令来检查它.
  5. 设置QT_PLUGIN_PATH 运行时变量可能有助于加载插件.它应该指向包含插件目录的目录,而不是插件目录本身.
  6. 您还可以启用跟踪以查看加载插件时发生的情况,以便更好地了解问题 - 导出 QT_DEBUG_PLUGINS=1QML_IMPORT_TRACE=1 环境变量
  1. Module identifier in qmldir should be the same as the directory name, where the module actually resides. For example if your module has module identifier module Test.Module in qmldir, your module's relative path must be Test/Module.
  2. If it is a QML extension plugin (shared library), make sure that plugin's directory name is the same as plugin's name.
  3. export QML2_IMPORT_PATH (make sure there is 2 in the name) env variable to point to directory containing your module. There is also a QQmlEngine::addImportPath method, which adds the directory to the list to lookup for plugins.
  4. If it is a qml extension plugin (shared library), then there might be missing dependencies for it. You can check it by Dependency Walker on Windows or ldd command on Linux.
  5. Setting QT_PLUGIN_PATH runtime variable may help to load plugins. It should point to a directory containing you plugin's directory, not the plugin's directory itself.
  6. You can also enable traces to see what's going on while plugins are loaded for better understanding of the problem - export QT_DEBUG_PLUGINS=1 and QML_IMPORT_TRACE=1 environment variables

您也可以阅读此链接:https://doc.qt.io/qt-5/qtqml-modules-identifiedmodules.html

这篇关于未安装 Qt5 QML 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆