0

I try to create an application in which I use rcc modules but I get the error "modules not installed".

I have the following folders and files:

MainFolder
  |_Folder1
    |_Folder11
       |_qmldir
       |_MyButton.qml
  |_Folder2
    |_qmldir
    |_MyComponent.qml
Application
  |_application.pro
  |_main.cpp
  |_main.qml
  |_rccFolders
    |_folder11.rcc
    |_folder2.rcc   

My qmldirs contain:

In Folder11:

module MainFolder.Folder1.Folder11
MyButton 1.0 MyButton.qml

In Folder2:

module MainFolder.Folder2
MyComponent 1.0 MyComponent.qml

The main.cpp:

 #include ...

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

  QString sourcePath="C:/path_to_rcc_files/";
  QQmlApplicationEngine engine;

  QResource::registerResource(sourcePath+"folder11.rcc");
  QResource::registerResource(sourcePath+"folder2.rcc");

  engine.addImportPath(":/"); //to use .rcc files
  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

  return app.exec();
}

The main.qml:

//QML imports
import MainFolder.Folder1.Folder11
import MainFolder.Folder2

ApplicationWindow
{
  ...
}

But when I execute the application, I get:

qrc:/main.qml:... module "MainFolder.Folder1.Folder11" is not installed
qrc:/main.qml:... module "MainFolder.Folder2" is not installed

What is wrong in my code? Thanks.

SteveTJS
  • 635
  • 17
  • 32

2 Answers2

0
  1. You may debug resource problems (go to Debugging section at the end) using QML_IMPORT_TRACE

  2. It says import <ModuleIdentifier> <Version.Number> [as <Qualifier>] so be sure to try:

 import MainFolder.Folder1.Folder11.MyButton 1.0
 import MainFolder.Folder2.MyComponent 1.0
KYL3R
  • 3,877
  • 1
  • 12
  • 26
  • Sorry but I can't understant with the doc how to use that QML_IMPORT_TRACE. I added it to environment variables with value 1 but how do I get the trace? They say "before running the QML Scene", what does that mean? – SteveTJS Apr 25 '18 at 08:12
  • Do you use and IDE, or compile via console? In windows, open cmd, navigate to executable, use `SET QML_IMPORT_TRACE=1` and then run the exe. Output is shown in console – KYL3R Apr 25 '18 at 08:21
  • I use QtCreator. – SteveTJS Apr 25 '18 at 08:24
  • There should be a "Application output" tab – KYL3R Apr 25 '18 at 08:45
  • It works, I have the outputs. In fact, you have to close and open QtCreator again to take the environment variable QML_IMPORT_TRACE into account. So I'll search my module error with that. – SteveTJS Apr 25 '18 at 09:47
  • If you find the cause, report back :) – KYL3R Apr 25 '18 at 10:24
0

Maybe you could try to use an import path with qrc: prefix:

engine.addImportPath("qrc:/");

I am not completely sure (and actually the documentation says both the :/ and qrc:/ notations should work), but I remember I had some similar issues in the past. At least in my apps (where I use a similar structure) I always use the qrc:/ prefix.

Martin Höher
  • 715
  • 5
  • 9