Qt5 QML module is not installed

jkj yuio picture jkj yuio · Feb 12, 2016 · Viewed 30.1k times · Source

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

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:

  • what does it mean by "installed". I have directory of files, but i haven't "installed" them anywhere.
  • should i be building/compiling the module to make a DLL/.so ?
  • does the module QML files go into the resources of the main app, otherwise where are they to be found?
  • my main.qml file is part of the app resources, how does the app locate the resources of the module at runtime.

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.

thanks for any help.

Answer

rightaway717 picture rightaway717 · Feb 12, 2016

I'll try to answer your questions:

  • 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. 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

You can also read this link: https://doc.qt.io/qt-5/qtqml-modules-identifiedmodules.html