[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/
    --main.qml
    ---Screens/
    --Second.qml
    --Third.qml
    ---Components/
    --Keyboard.qml
    --Gallery.qml
    --BackButton.qml
    --KeyboardSubComponents/
    ---Keyboard_buttons.qml
    ---Keyboard_display.qml
    @

    etc.
    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?

    Thanks.



  • 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:
    @<RCC>
    <qresource prefix="/qml"/>
    <qresource prefix="/qml/Main">
    <file>qml/test4/Main/main.qml</file>
    </qresource>
    <qresource prefix="/qml/Components">
    <file>qml/test4/Components/Keyboard.qml</file>
    </qresource>
    </RCC>
    @

    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;
    viewer.setSource(QUrl("qrc:/qml/Main/qml/test4/Main/main.qml"));
    viewer.showExpanded();
    
    return app.exec();
    

    }
    @

    This doesn't work anymore



  • Hi,

    You shall remove prefixes. QRC file shall look something like that:
    @<RCC>
    <qresource prefix="/">
    <file>qml/main.qml</file>
    <file>qml/theme/Theme.qml</file>
    ...
    </qresource>
    </RCC>@

    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":http://stackoverflow.com/questions/20104514/how-to-load-qml-file-from-resources-using-qtquick-2-controls



  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.