0

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?

MelMed
  • 255
  • 10
  • 19
  • How you load them? How you deploy them? How you include them in the project? How you need to include them (embedded?) – Adriano Repetti Jul 23 '13 at 09:38
  • @Adriano See the edit above. – MelMed Jul 23 '13 at 09:39
  • Maybe just use relative path? If so, just copy this files to your working directory (check working directory in project settings). Also you can try use resource file to embed files to your execute. – user1837009 Jul 23 '13 at 09:54

1 Answers1

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.

  • Hint for MSVC: Right click on project -> Add... -> New Item... -> Qt Resources. You will get .qrc file in your project. Doubleclick on it and add resources there. You can copy/modify path-to-your-resource in qt resource editor (looks like ":/images/button1.png"). – Dmitry Sazonov Jul 23 '13 at 10:15