Adding image to QLabel using QPixmap
Hello,
I'm trying to add a label as an image. So I've created a resource under Qt and added in the images, but when I try to run the code it only adds in the image if I give it the extact path and not the short version.
For example:
This works
Code:
void MainWindow::TestIOinputs()
{
QPixmap stat_GO
("C:/Qt/MyProject/images/stat_noGO.png");
ui->label_3->setPixmap(stat_GO);
}
This doesn't work
Code:
void MainWindow::TestIOinputs()
{
QPixmap stat_GO
(":/images/stat_noGO.png");
ui->label_3->setPixmap(stat_GO);
}
The resource file is called images and I have added the images there. I can also see that the .pro file has the resources.qrc added in. Any ideas?
Re: Adding image to QLabel using QPixmap
Make sure the prefix is the same as you set it in the resource file. If you are using Qt Creator you can right click the image file in the list of files and copy its path to clipboard.