Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML files in resource of library not found in app using the library



  • Hello friends,

    i have the following setup:

    mylib

    • mylib.qrc (containing QML and SVG)

    myapp

    • myapp.qrc (also containing QML and SVG)

    Now when i want to access a QML component which is located in the mylib.qrc from a QML compomnent which is in the myapp.qrc it is not known and i get the error "XXXX is not a type"

    What do i need to make that the QML components from the resource inside my lib (mylib.qrc) gets available to the applications QML components which uses the lib?
    I already tried Q_INIT_RESOURCE(mylib) in my main.cpp directly after QGuiApplication app(argc, argv) but it seems not to work...

    Thank's for your help :)

    Greetings
    Nando


  • Moderators

    @Nando said in QML files in resource of library not found in app using the library:

    I already tried Q_INIT_RESOURCE(mylib) in my main.cpp directly after QGuiApplication app(argc, argv) but it seems not to work...

    It should work. Once a resource is loaded, QML engine does not care which QRC file the data is coming from.

    So I'd suggest first to make sure that Q_INIT_RESOURCE worked well - try opening some file from mylib.qrc in your main.cpp, using QFile.

    Second step is to make sure your prefix / path inside QRC is correct. Lastly, make sure there is no conflict for file you want to access (is the same file name registered in both QRC files?).

    Plus, of course, if your component is part of a QML module qmldir, you have to register it's import path with QML engine.



  • @sierdzio Hi and thank you.
    I tested it with opening a file inside the mylib.qrc from my app using QFile and it works fine.

    But every time a QML component from myapp.qrc tries to use a component from mylib.qrc i still get the error 'xxx is not a type'

    No duplicate file names.

    What do you mean with:
    Plus, of course, if your component is part of a QML module qmldir, you have to register it's import path with QML engine?

    I just have a qml directory in my lib root dir and a qml directory in my app root dir.
    Each (lib and app) has its own .qrc file referencing the QML files from theire qml directory...

    It would be really nice if you could help me a bit further.

    Thank you :)

    Nando


  • Moderators

    @Nando said in QML files in resource of library not found in app using the library:

    I just have a qml directory in my lib root dir and a qml directory in my app root dir.
    Each (lib and app) has its own .qrc file referencing the QML files from theire qml directory...

    OK, please post some of the QRC code (from both .qrcs) here, as well as the import statements from QML and how you call the component which fails to load. My guess is that some import is missing, or wrong path is provided, or something similar - but without concrete data it's hard to say anything specific.


Log in to reply