Including images and a file to a project

梦想的初衷 提交于 2019-12-13 07:02:22

问题


I m having some images that I load from some paths C:/....png to display them in a user interface, and a file that I would like to insert whithout specifying everytime its path

I tried to include images in my project and access them directly without specifying their addresses, especially that I would work on many machines and I don't want to change the path everytime, and create folders and images again. It didn't work!

I use a QPixmap to load images and have access to the image like what is follow:

QPixmap image("C:/images/image.png");

Even if I include that file to the project (image.png), when doing

 QPixmap image("image.png"); 

the image is not found and pixmap is having nothing.

As for the file, it's a text file that I would like to insert to the project. "myFile.txt" which exits at:

C:/images/myFile.txt

Any ideas how to resolve that?


回答1:


I recommend using Qt's resource system. It allows you to store the images inside the executable, which is usually more convenient than having a lots of files alongside the executable.



来源:https://stackoverflow.com/questions/17806552/including-images-and-a-file-to-a-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!