QML import rcc modules

796 Views Asked by At

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.

2

There are 2 best solutions below

6
On
  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
0
On

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.