Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to load a shared library resource

how to load a shared library resource

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 583 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rafael
    wrote on last edited by rafael
    #1

    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)
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

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

        R Offline
        R Offline
        rafael
        wrote on last edited by rafael
        #3

        @SGaist

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved