I have to make a chess game with graphics and this is a part of my code for the board and a chess piece. I have made the chess board and now I am trying to add in a chess piece which is an image I have downloaded. I have the code but I need to somehow put the chess piece image into my build directory for the piece to actually appear on the board. I am using QT creator on a mac and can not figure it out.
for (int x=0; x<8; ++x) {
for (int y=0; y<8; ++y) {
if((x+y+1)%2==0) {
paint.fillRect(x*44,y*44,44,44,QColor(177,113,24));
} else {
paint.fillRect(x*44,y*44,44,44,QColor(233,174,95));
}
QImage image;
image=QPixmap("wrook.gif").toImage();
paint.drawImage(0*44,7*44,image);
}
}
You can use resource files to add different types of files to your Qt application without dealing with their origin in the hard-drive. If you are using Qt Creator just click "File -> New file or Project" select "Qt -> Qt Resource file" add prefix (they are like directories inside the resource file) and copy there your images. Them to load those files use this code :