I'm trying to insert an image to my program via resource file, which is like:
<RCC>
<qresource prefix="/">
<file>green.png</file>
<file>other files</file>
</qresource>
</RCC>
and when I'm trying to load it using QImage or QPixmap, like:
QImage *green = new QImage(":/green.png");
if(green->isNull()) qDebug("null");
I always see that null message, indicating that I'm doing something wrong. One solution may be using absolute path like
"C:\\Users\\user\\Documents\\project\\green.png",
which works of course, but I'd prefer implement it using resource file. Could you please give me some advice?
First of all, you need to create a .qrc file and add image folder to it
then go to mainwindow.cpp (in my project ) file and call the images as below code
ui->play->setIcon(QIcon(":/Playericons/icons8-pause-30.png"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With