I'm trying to load images from my resources.qrc but it doesn't seem to work. For instance:
cardVN1->setImage("://vn1.jpg");// The set image function is user-defined passing a QString
void CustomCard::setImage(QString img_path){
QImageReader imageReader(img_path);
if(!imageReader.canRead()){
qDebug()<<"Cannot load image resource!";
return;
}
QSize img_size = imageReader.size();
int w = img_size.width();
int h = img_size.height();
QPixmap image(img_path);
setStyleSheet("QPushButton{height: w}");
imageView->setPixmap(image.scaled(w,h, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
My resources.qrc looks like:
<RCC>
<qresource prefix="/images">
<file>vn1.jpg</file>
<file>vn2.jpg</file>
</qresource>
</RCC>
It has been registered in my CMakeLists.txt as:
qt_add_executable(MwendwaLB
WIN32 MACOSX_BUNDLE
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
customcard.h customcard.cpp
assets.qrc
)
Any anomalies or suggestions?
UPDATE: I was able to fix the error. I had to add
SET(CMAKE_AUTORCC ON)
in my CMakeLists.txt.