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

[SOLVED] - Get in trouble with resource file



  • Well, I want add icon at project. I follow " this guide ":http://doc.qt.nokia.com/qtcreator-2.3/creator-writing-program.html 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">
    <qresource>
    <file>images/icon.png</file>
    </qresource>
    </RCC>@

    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)

    !http://nn2.upanh.com/b6.s27.d2/f61458c20b96967cffebd8dbe08de609_45928952.h1.png(1)!

    Really, It must have following structure: :)

    !http://nn0.upanh.com/b4.s26.d1/b3d86be905d09bfcffd3b0175bbc714d_45929000.h2.png(2)!

    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:

    !http://img401.imageshack.us/img401/2613/47682466.png(qrc)!

    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