Important: Please read the Qt Code of Conduct -

[SOLVED] - Get in trouble with resource file

  • Well, I want add icon at project. I follow " this guide ": to create resource file. We also know folders as Headers, Sources, Resources are only "logical" folder which Qt creator built to manage easily. But really I see file .qrc was placed in Resources, In folder root project, I created 1 folder to store image called "images", so folder "physical" images have level equivalent as folder Resources in tree? If I write content of file .qrc following:

    @<!DOCTYPE RCC><RCC version="1.0">

    File .qrc is placed in Resources folder can "see" file .png in folder images?

  • Maybe I find a little mistake, resource file itself uses a XML format.

    First, I think it's so: (rc.txt contain code XML above)


    Really, It must have following structure: :)


    ps: Author of some books has sense of humor, they describe content of file .qrc while we never have opportunity to see it.

  • The prefix you use in the resource file can be something else than the folder you use on your hard disk.
    Eg. If you have a folder /images, you can use a prefix /img in the resource file.

    When you use Qt Designer / Qt Creator, you use the add button to browse for image files on your hard drive. I always do it like this. You could try it out and afterwards have a look at the file to see how it works.

  • @Eddy: Having something I don't understand. I modify prefix following:


    I think when I add file icon.png at tree. It only shows file name (icon.png), in fact, it still need name of folder containing it (images/icon.png) ?

  • The /images/icon.PNG has that extra path info because it is in a subfolder /images.

    Have you tried using the icon.png using Qt Creator?
    Go to a ui and add a QLabel to it. Then in the properties of that label go to pixmap, click on the button on the right (shows up when you click in inputfield) and a dialog appears which shows your resource system. Click on the icon.png and you should see it in your widget.

    tip: don't forget to save your qrc file after making changes to it.

  • Thanks so much :)

  • You're welcome.

    If your issue is solved please add [solved] to the title of this topic by editing your first post. Thanks.

Log in to reply