Unsolved how to load a shared library resource
-
I am struggling to load a pixmap from a library, i have added
RESOURCES += ../Base/cards.qrc
in the .pro file.
I have added
Q_INIT_RESOURCE(cards); in the main file
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); Q_INIT_RESOURCE(cards); return a.exec(); }
If the path it hard coded the images show up correctly.
what am i missing?MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // this works //QPixmap p("C:/Users/Home/Documents/PokerGame/Resources/2C.png"); // this does not work //QPixmap p("qrc:/../Resources/2C.png"); // this does not work //QPixmap p(":/../Resources/2C.png"); ui->label->setPixmap(p.scaled(80,100)); } ![0_1555364015547_structure.png](https://ddgobkiprc33d.cloudfront.net/93cbee33-492a-49fb-a238-0ea61084bb1f.png)
-
Hi,
You might want to load it before trying to use its content.
-
i tried this
QPixmap p; p.load(":/../Resources/2C.png");
weirdly i did
p.load(":Resources/2C.png"); and this one works. why is that?shouldn't the url path from the resource folder be the correct path.
the first one i copied the path from the resource folder. -
I don't know the structure of your project nor the content of your .qrc file so I can't answer.