Important: Please read the Qt Code of Conduct -

[Solved] Resources and folders

  • Hello

    I need a little help here.

    I want to save qmls in folders so they are easier to find and work with, but I don't know how to deal with the resources system when doing this. (If all files are saved in the same directory it works fine but it's a mess)

    So let's say that my filesytem is:
    @ ---Main/

    And that my resource file follows the same hierarchy.

    If I try to load keyboard component from main.qml such as
    @Keyboard {
    id: keyboard

    qtcreator complains that it doesn't know what "Keyboard" is, so I guess it has something to do with imports.

    I've tried lots of combinations but none of them worked.

    Any clue?


  • in main.qml

    import "../Components"

  • Thank you. Unfortunately this only works if I don't use the qt resource system.

    If I use it, so my resource file looks like this:
    <qresource prefix="/qml"/>
    <qresource prefix="/qml/Main">
    <qresource prefix="/qml/Components">

    And my main.cpp looks like this:
    @#include <QtGui/QGuiApplication>
    #include "qtquick2applicationviewer.h"

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

    QtQuick2ApplicationViewer viewer;
    return app.exec();


    This doesn't work anymore

  • Hi,

    You shall remove prefixes. QRC file shall look something like that:
    <qresource prefix="/">

    Then relative paths act as they are on real FS.

    Note, most likely you will have to modify QtQuick2ApplicationViewer::setSource to get it working with QRC-based system, "see here":

  • Thank you. That worked.

    I was expecting that I could maintain the same hierarchy on the resources file too so it could be cleaner and more organized, but it seems that you can't do that.

    Anyway, this solutions is good enough for me since it allows me, at least, to keep my files organized.

Log in to reply