Take the 2-minute tour ×

I have a resource at :images/pic.gif

Can I make a QPicture from this resource or does it have to be loaded from file?

share|improve this question
What do you mean by "make a QPicture from this resource"? –  liaK Jun 8 '10 at 6:43
add comment

3 Answers

QPicture is for recording QPainter commands, not for image data. If you want to load an image, use QPixmap or QImage. You can use their load() methods. To access an image file bundled as a resource, use ":/" to access the resource: ":/someFile.png". The exact paths and filenames are specified in the qrc files.

share|improve this answer
add comment

I think your question is like after adding images/pic.gif into the resource file whether it has to be accessed from the resource file or the directly the location of images/pic.gif.

Now my answer for the question is, even if you have added the images into resource file and accessing it, it will indirectly access the physical file itself. To illustrate this, after adding the images/pic.gif into the resource file, try removing the images/pic.gif from the location and access within your application. You will not able to get the image. So, even if you add it into the resource file it is similar to access the physical file present in its original location. Check out the Qt Resources page.

But it is a good practice and logical to organize your required files into a resource file so that all the required files are present in the same location.

Using QPicture you can load it into your application through

bool QPicture::load ( const QString & fileName, const char * format = 0 )
share|improve this answer
add comment

you have to use Qicon or Qpixmap to load the images from resource. QPIcture is used to save the picture.

share|improve this answer
add comment

Your Answer


