Search code examples
qtqt-resource

Adding files to the Qt resource system


I have added a JPG file to the QRC resources to not drag every time the full path of the image file.

However, it's not displayed when I am starting the user interface where it's supposed to be loaded.

I added to it an alias. It's not working. But when I write the name of the file included in the project solution, it's well displayed.

PS: I want to organize my project and put the file in QRC resources.

This is how I did it:

QPixmap img(":/projet/image.jpg"); // It's not loaded
QPixmap img("image.jpg"); // It's OK

Solution

  • Check your .qrc file first.

    You can check your file with another editor like notepad++, vim, joe etc.

    Does it look similar to this example:

    <RCC>
        <qresource prefix="/project">
            <file>FOLDER/image.jpg</file>
        </qresource>
    </RCC>
    

    If it does, you can access your image through:

    QPixmap example(":/project/FOLDER/image.jpg");