Extreme confusing problem
-
Have you tried to use the resource icon in your real code??
To show an Item in a GraphicsView you have to set correctly GraphicsScene rect and the view
This code
ui->label->setPixmap(QPixmap(":/images/image.png"));
works well for me using the resource
<RCC> <qresource prefix="/images"> <file>image.png</file> </qresource> </RCC>
-
@Rondog Thank you Randog, But it is not the problem.
I think that this line might be unnecessary. But you brought this up, I have another question for this line.
I have tried this even before I asked here. And when I add this line to my main.cpp, It told me " LNK2019 unresolved symbol".
There is an example in Qt document using this line, and I had the exact same libraries included.Note:
- resource file has been included in .pro file.
- Q_INIT_RESOURCE(Ima); /* name of my qrc file is Ima.qrc now*/
-
The unresolved linker error will occour if the name inside the macro Q_INIT_RESOURCE cannot be found.
I was not aware that this wasn't required, I tried it and sure enough it worked without it. It is interesting that when you did add it you ended up with a link error which means it can't be loaded (I have always added this line inside of main and get this error when I don't set the name properly).
From a sample program I have the following (that does work):
// qrc file ===================== <!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="/gui"> <file>autocapture.png</file> </qresource> </RCC> // pro file ===================== // note: I put all the resources in a folder called 'res' RESOURCES += res/autocapture.qrc // usage example ===================== d_start_button->setIcon(QIcon(":/gui/autocapture.png"));
A couple of observations that might be helpful.
The resources line in the .PRO file ...
RESOURCES += \ Ima.qrc
... might be a problem. Why not this instead:
RESOURCES += Ima.qrc
The .qrc file is missing the first XML identification line (i.e. '<!DOCTYPE RCC>' ). Maybe the file is not recognized as a resource file without this line?