PDA

View Full Version : Qt resources not working



franco.amato
21st November 2015, 20:10
Hi to all,
I migrated some weeks ago to Qt 5.5 ( from Qt 4.x ) and resources mechanism stopped working ( at least on my machine ).
Looking at the documentation, seems the same as per Qt 4, so I followed the same logic.

In my project structure I have a folder named Images containing some icons that I would add to a toolbar.

Here my simple resources.qrc file:


<RCC>
<qresource prefix="/MyFiles">
<file>Images/cut.png</file>
<file>Images/bringtofront.png</file>
<file>Images/colors.png</file>
<file>Images/copy.png</file>
<file>Images/delete.png</file>
<file>Images/link.png</file>
<file>Images/node.png</file>
<file>Images/paste.png</file>
<file>Images/sendtoback.png</file>
</qresource>
</RCC>

And here the c++ code that does not have any effect



addNodeAction = new QAction(tr("Add &Node"), this);
addNodeAction->setIcon(QIcon(":/MyFiles/Images/node.png"));
addNodeAction->setShortcut(tr("Ctrl+N"));
connect(addNodeAction, SIGNAL(triggered()), this, SLOT(addNode()));


I tried many path combinations, none of them is working:


addNodeAction->setIcon(QIcon(":/Images/node.png"));
addNodeAction->setIcon(QIcon("://MyFiles/Images/node.png"));
addNodeAction->setIcon(QIcon(":/node.png"));


I hope to get some help

Regards

Qiieha
22nd November 2015, 07:50
Try to create a QPixmap instance and check if its not null. If so your ressources work.
So check for the plugins, which handle the showing of pictures, like your png's, in qt applications.

anda_skoa
22nd November 2015, 07:52
Use something like Gammaray to inspect the resource tree in the running application or use QDir starting at :/ to list the resource tree manually.

Cheers,
_