Qt Image from resource file

前端 未结 3 952
小鲜肉
小鲜肉 2021-01-18 06:18

I\'m trying to insert an image to my program via resource file, which is like:


    
        green.png&l         


        
3条回答
  •  耶瑟儿~
    2021-01-18 06:30

    All this will work if your png files are located in the same folder as .pro, .qrc, and .cpp files of your project.

    Usually it is convenient to put all images to special subfolder Resources, for example. Then in .qrc the line will look like:

    Resources/green.png
    

    And in .cpp file:

    QImage *green = new QImage(":/Resources/green.png");
    

提交回复
热议问题