1、最好(图像资源等都包含在一个文件夹中,如images)
2、在main函数中强制初始化资源Q_INIT_RESOURCE(filename);如:
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(filename);
//资源定义宏
...
}
3、在工程文件*.pro中添加行:
RESOURCES += application.qrc
4、典型的*.qrc文件
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/actualsize.png</file>
<file>images/fitwindow.png</file>
<file>images/present.png</file>
<file>images/print.png</file>
<file>images/rotate_left.png</file>
<file>images/rotate_right.png</file>
<file>images/zoomin.png</file>
<file>images/zoomout.png</file>
<file>images/next.png</file>
<file>images/previous.png</file>
<file>images/copy.png</file>
<file>images/open.png</file>
</qresource>
</RCC>
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
5、资源引用,如:
QIcon(":/images/open.png")
%调用images文件夹中的open.png。
*注:若是通过添加qrc获得的文件,则需要注意文件中类似“<qresource prefix="/new/prefix1" >”之类的前缀,也需要添加在文件前,如QIcon(":/new/prefix1/images/open.png");注意与上文的不同。