一般使用使用相对位置的时候可能无法显示图片,可能是由于文件的相对位置错误。
#include<QDir>
#include<QDebug>
QDir dir;
QString pathname;
pathname = dir.currentPath();
qDebug()<<pathname;
以上语句可以找到当前工程的目录,然后将图片文件复制到当前文件下就可以了。
比如我的一个程序运行后如下:
"E:/QTfiles3/build-timeCount-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug"
可见是在debug文件下的。
图片引用方法如下:
QPixmap pic("images/timer_bg_360x640.png");