将图像和文件包含在项目中 [英] Including images and a file to a project
问题描述
我有一些图像,我从一些路径加载C:/ .... png以在用户界面中显示它们,以及我想要插入的文件,而不是每次指定其路径
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!
我使用QPixmap加载图像并可以访问图像,如下所示:
I use a QPixmap to load images and have access to the image like what is follow:
QPixmap image("C:/images/image.png");
即使我将该文件包含在项目中(image.png),也一样
Even if I include that file to the project (image.png), when doing
QPixmap image("image.png");
找不到图像,pixmap什么都没有。
the image is not found and pixmap is having nothing.
至于文件,它是我想要插入项目的文本文件。 myFile.txt退出:
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
任何想法如何解决?
推荐答案
我建议使用 Qt的资源系统。它允许您将图像存储在可执行文件中,这通常比在可执行文件旁边有大量文件更方便。
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.
这篇关于将图像和文件包含在项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!