问题
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