PDA

View Full Version : QPixmap loading from resources problem on Windows



jrak
21st December 2013, 11:28
I have a problem with loading QPixmap from Qt Resources on Windows 8. I added image pawn.png (with resource editor from Qt Creator) which is in project's directory. Resource editor file res.qrc is in the same place as image. Here is the content:

<RCC>
<qresource prefix="/">
<file>pawn.png</file>
</qresource>
</RCC>

The code for loading image:

QPixmap pawn;
if(!pawn.load("://pawn.png"))
std::cout << "Can't load image" << std::endl;
scene->addPixmap(pawn);

There is always printed "Can't load image". I've tried probably all slash/backslash combinations in image path, nothing works. The one above is generated with right clicking in Resource Editor on image and "Copy Resource Path to Clipboard". Can anyone help?

anda_skoa
21st December 2013, 13:48
It is only one forward slash, but otherwise this looks ok.

Try listing the resource root, e..g


QDir dir(":/");
qDebug() << dir.entryList();


Cheers,
_

jrak
21st December 2013, 14:51
It returns "qt-project.org". How can I change this? I thought that project's directory is root for resources by default.

anda_skoa
22nd December 2013, 11:26
Yes, you are just seeing the "directory" of Qt's own resources.

Meaning yours are not there.

Check that your resource file is properly listes in your .pro file and rebuild.
Check that the build directory has the generated qrc_resourcefilename.cpp file

Cheers,
_