3

I am new in QML and I have a project. In one of my directories I have /imports/system/qmldir file where I have he following code:

singleton System 1.0 System.qml
App 1.0 App.qml

and in my source file I have

import system 1.0

And the error says that module system is not installed.

qrc:/Main.qml:24 module "system" is not installed

Could you please tell me the steps or flow of installing the module.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
Eduard Rostomyan
  • 7,050
  • 2
  • 37
  • 76
  • Related - https://stackoverflow.com/questions/35352930/qt5-qml-module-is-not-installed. Also can you post the exact error message? – sashoalm Sep 13 '16 at 14:24
  • qrc:/Main.qml:24 module "system" is not installed – Eduard Rostomyan Sep 13 '16 at 14:26
  • See https://forum.qt.io/topic/50037/qml-included-modules-not-installed-unless-qml-directory-is-a-subdirectory-of-the-project-file/3. In it they say *"You need to set QML_ROOT_PATH in your .pro file to the path to the directory with your QML files. The default value is your project directory, that's why it works when you put your qml's right there."* Is Main.qml in your project root, or in a subdir? – sashoalm Sep 13 '16 at 14:31
  • my Main.qml is in project root, on the same level as .pro file. – Eduard Rostomyan Sep 13 '16 at 14:36

1 Answers1

4

You must call QQmlEngine::addImportPath() and pass the path to /imports.

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.addImportPath("/path/to/imports"); // <==
    engine.load(...);

    return app.exec();
}
jpnurmi
  • 5,716
  • 2
  • 21
  • 37