Question

When i have this code and copy manually i.png to binary file destination

scene = new QGraphicsScene(this);
QPixmap pixm(qApp->applicationDirPath() + "/i.png");
scene->addPixmap(pixm);
ui->graphicsView->setScene(scene);

Image shows exactly as i want. Now i created resource file images.qrc. Path is set to / and contains only one file i.png. But when i change code to:

scene = new QGraphicsScene(this);
QPixmap pixm(":/images/i.png");
scene->addPixmap(pixm);
ui->graphicsView->setScene(scene);

GraphicsView remains empty. Why?

There is images.qrc

<RCC>
    <qresource prefix="/">
        <file>i.png</file>
    </qresource>
</RCC>
Was it helpful?

Solution

":/images/i.png" assumes that the prefix is images. Rather use

 QPixmap pixm(":/i.png");

OTHER TIPS

In order to specify the location of :/images/i.png, I'd expect the resource file to look more like this: -

<RCC>
<qresource prefix="/images">
    <file alias="i">images/i.png</file>
</qresource>
</RCC>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top