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

QRC add folder



  • Hi,

    I'm trying to read a folder's content who contains another folder and files in theses folders.
    The organisation of the content can be resume with the following schema:

    - Ressources
        - fileressource
        - fileressource
        - ...
        - players
            - player1
                - info.txt
                - icon.png
                - sprite.png
            - player1
                - info.txt
                - icon.png
                - sprite.png
        - fileressource
    

    What i want is to get something like this:

        QStringList playersFolder = QDir(":players").entryList(); // Expected { "James", "Maximus" } (without take in account dot and dotdot)
        for (auto playerFolder : playersFolder) {
            QString pathInfo = playerFolder + "/info.txt";
            QString pathIcon = playerFolder + "/icon.png";
            QString pathSprite = playerFolder + "/sprite.png";
        }
    

    But what I have is playersFolder = {"icon.png", "info.png", "James", "Maximus", "sprite.png"}

    My QRC is like this:

    <RCC version="1.0">
        <qresource>
            <file>players</file>
        </qresource>
    </RCC>
    

    So i'm confused


  • Lifetime Qt Champion

    That's not how the resource system is working. You either build the resources as part of your application or build an external binary resource.

    You have all the information you need here.


  • Lifetime Qt Champion

    Hi,

    AFAIK, and following the documentation, you are expected to list all files explicitly in the .qrc file. I am currently surprised you are not getting an error when compiling your application.



  • @SGaist thanks for your answer, there is no way to don't list all files in the qrc? I want to do this dynamically.

    If there is no way, I'll going to try to add a file resource "folder.json" for example who going to list all directory (name + path)


  • Lifetime Qt Champion

    What do you mean by "I want to do this dynamically" ?



  • Don't list files in the qrc, simply open the folder and get the content. If I add, for example, new sub-folders into the main-folder, the program doesn't need to be recompiled, when I open the folder, I will see all sub-folders.


  • Lifetime Qt Champion

    That's not how the resource system is working. You either build the resources as part of your application or build an external binary resource.

    You have all the information you need here.



  • @SGaist Yes, I have already read this document ;) thanks for the explanation !


Log in to reply