Important: Please read the Qt Code of Conduct -

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;;
        return a.exec();

    If the path it hard coded the images show up correctly.
    what am i missing?

    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        // 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");

  • Lifetime Qt Champion


    You might want to load it before trying to use its content.

  • @SGaist

    i tried this

    QPixmap p;

    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.

  • Lifetime Qt Champion

    I don't know the structure of your project nor the content of your .qrc file so I can't answer.

Log in to reply