Qt:Resource
The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.
Resource Collection Files
The resources associated with an application are specified in a .qrc file, an XML-based file format that lists files on the disk and optionally assigns them a resource name that the application must use to access the resource.
Here's an example .qrc file:
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/copy.png</file>
<file>images/cut.png</file>
<file>images/new.png</file>
<file>images/open.png</file>
<file>images/paste.png</file>
<file>images/save.png</file>
</qresource>
</RCC>
How to use
소스코드와 같은 위치에 다음과 같은 내용의 resources.qrc 파일을 작성합니다.
마지막으로 프로젝트파일(.pro)에 다음 한줄을 추가합니다.
:/
로 시작하는 경로는 리소스 파일에 대한 경로입니다. 이와 같이 리소스로 추가된 파일을, 실제 소스코드내에서 불러올때는 반드시 :로 시작하는 경로를 입력해야 합니다./
는 리소스 목록 파일에서 prefix로 지정된 경로로, 만약 prefix=”/rsc”
와 같이 지정했었다면 가 아니라 :/img/document-new.png
:/rsc/img/document-new.png
와 같이 해야 할 것입니다.