QPixmap .png in the same project directory
I want to create a Qpixmap object with a .png that is in a subfolder within the same project directory without typing in the entire path.I think there is a way to do this. But for the life of me i cant remember.
so instead of typing
QPixmap* pixmap = new QPixmap("c:\documents and settings\....\projects\program01\cards\1.png");
QPixmap* pixmap = new QPixmap("cards\1.png") or something?
Why you do not use "The Qt Resource System":http://doc.qt.nokia.com/latest/resources.html ?
You can access the path of your application by calling "applicationDirPath":http://doc.qt.nokia.com/latest/qcoreapplication.html#applicationDirPath
If you want the native separator of folders on your system, you have "QDir::separator":http://doc.qt.nokia.com/latest/qdir.html#separator
By the way, do you really need a pointer to your QPixmap ?
Otherwise, you still can use the Qt Resource System, as stated above :)
@QPixmap* pixmap = new QPixmap("some.png");@
This is should work. Since you are not using the resource system, you must do one thing :) . Copy the image to build directory.
According to "doc":http://doc.qt.nokia.com/latest/qpixmap.html#QPixmap-4
bq. If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.