0

I need to initialize a qpixmap object with its file directory

It works if I do the following: image = new QPixmap("C:/Users/Administrator/Desktop/maze/HTetris-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug/untitled/c12.bmp");

and it works with as well: image = new QPixmap("/Users/Administrator/Desktop/maze/HTetris-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug/untitled/c12.bmp");

But this is just too long and too specific. I have put c12.bmp in the same file as the project itself. But image = new QPixmap("c12.bmp");

simply does not work.

Since this project needs to be portal, how can I do!!!!!!!

Thanks guys for help

user1819047
  • 667
  • 9
  • 18

2 Answers2

0

Consider to put your file into resource file (qrc) or put your file near your executable file, because your "c12.bmp" is searched in runtime and must be in the same with executable directory.

AnatolyS
  • 4,249
  • 18
  • 28
0

You file must be in the file where your application is executed (runtime directory) that can be different than the directory of the executable.

You can use resource files for the portablity (your pixmap will be "embedded" in your binary).

http://qt-project.org/doc/qt-4.8/resources.html

Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37