PDA

View Full Version : .qrc



Atomic_Sheep
24th September 2012, 17:03
This is taken directly from the documentation:

"In particular, you can pass a resource path instead of a file name to the QIcon, QImage, or QPixmap constructor:"

I created a .qrc file into which I've input some .bmp files that I wish to use in my program and then I tried loading those images via:


QImage Image;
if(!Image.load(":/Images/sample.bmp")
{

Ufortunately, when I run the program, the image does not load. My folder structure is such that in the same directory as the .qrc file, I have a folder called Images in which I have my images that I'm trying to acces. If I simply use the direct system path to the image in the load function, everything works fine, but using the .qrc method, I can't seem to get the image to load.

EDIT: .pro has RESOURCES listed.

jovin
24th September 2012, 17:24
Try using quotation marks:

QIcon(":/images/ok.png") // works for me
QIcon(':/images/ok.png') // doesnt work for me

Edit: Lol, sorry. I misinterpreted your code. Actually " looks like ' and vice versa. >_>
How does your .qrc file look like?

d_stranz
24th September 2012, 18:00
The problem is not the resource string, it is probably because the image plugin to handle "bmp" format is not installed. "png" works because support for it is built in to Qt and does not require an image plugin.

There has been an extensive discussion on the forum in the last week or two over *exactly* this same question. Did you search the forum before asking? Maybe you should do that now. You might find this (http://www.qtcentre.org/threads/50742-why-do-icons-only-show-up-on-my-computer).

Atomic_Sheep
24th September 2012, 18:26
Thanks much appreciated. My apologies for not using the search function. I actually had an inkling that .png was going to work if I tried loading a .png file but decided to get to the bottom of the problem and to understand it more fully. Your link answers my quesiton... I'll investigate further. Once again thanks for the link and my appologies for being lazy. I hate people coming to forums and asking questions that have been asked a million times before unfortunately it will continue to happen perpetually. The main problem with using search and why people continually don't use it is because:

a.) before trying a search you don't know if spending time doing so will reap rewards

b.) even if you find a response, the amount of time it takes to read through all the hits is a lot more than typing up and posting a question.

The upside to simply asking the question rather than doing some work yourself is that overall... it takes less time to type up the question and for someone with the knowledge to redirect that person to the answer than for the person to spend a lot of time searching for that information themselves. As I said, I know where you are coming from and I have felt the same frustration but then I remember that it truly is the quickest way this way and then it becomes easier to push that frustration aside and answer the same stupid question yet another time :).

d_stranz
24th September 2012, 18:46
Even if you don't search, it pays to at least take a look at some of the posts on a regular basis because you'll never know when you might be faced with a similar issue and then remember, "I think I read something about that".

The solution to your original question is to either 1) convert your BMP files to PNG using some image conversion program (simple) or 2) use the BMP files and deploy the required image plugin DLLs along with your application in the right place so the executable can find them (harder). If all these are is toolbar or button images, my personal choice would be to spend a couple of minutes converting and avoid the hassles of creating an installer that did the right thing while making the distribution bigger.

Atomic_Sheep
27th September 2012, 12:08
What you suggest is certainly a great idea, I've been meaning to do just this for quite some time on a number of forums, however to get something out of such an activity, one requires a certainl level of knowledge which in C++ and Qt I do not yet possess.

d_stranz
27th September 2012, 15:27
one requires a certain level of knowledge which in C++ and Qt I do not yet possess.

Ah, but that's the whole point - you learn not only from the books, but by reading about the real solutions to problems that are posted here. This is probably the best forum for Qt out there. There are others, but the level of expertise here is generally higher, and people are always willing to help someone who has demonstrated through their question that they have worked at understanding and solving the problem on their own before posting here.

On the other hand, the ones who ask, "My code doesn't work. Why?" without supplying any further detail usually get the kind of response such a post deserves.