Resources files in Qt
-
Hello normally when i want to add one resource in c++ i normally do this.
resource.rc:#include "resource.h" icon RCDATA "C:/Users/android/Documents/icon.gif"
resource.h:
#ifndef RESOURCE_H_INCLUDED #define RESOURCE_H_INCLUDED #define icon "icon" #endif // RESOURCE_H_INCLUDED
main.cpp`:
#include <windows.h> #include "resource.h" using namespace std; int main() { string icon = "icon"; HRSRC res=FindResource(NULL,icon.c_str(),RT_RCDATA); int size=SizeofResource(NULL,res); HGLOBAL hRes=LoadResource(NULL,res); unsigned char *pRes=(unsigned char *)LockResource(hRes); HANDLE hFile=CreateFile("C:/Users/android/Desktop/icon.gif",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL); DWORD bytesWritten = size; //here i can use my resource again CloseHandle(hFile); return 0; }
With qt i can't use files with .rc extension i think i must to use qrc but what is the difference? Other thing i can make the same thing with Qt or only possible in C++. And if it will be useful use qrc files? in this case i'm using a little of windows to use my file again but because i dont know other way to use my resources, in the case of Qt i dont know well how will be. thx again!
-
What you described is not "what one would normally do in C++" but specific to MS Windows API, just saying. Please see The Qt Resource System for a comprehensive guide on Qt's way to embed resources.
-
What you described is not "what one would normally do in C++" but specific to MS Windows API, just saying. Please see The Qt Resource System for a comprehensive guide on Qt's way to embed resources.
-
The Qt way is to create a *.qrc file and pass it to Qt's resource compiler. If you use Qt Creator and qmake, then all the complexity will be hidden from you. This way works on all platforms (operating systems / compilers) that are supported by Qt. To learn more about resource handling in Microsoft Visual Studio 2015, see Resource Files (Visual Studio).