Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Resources files in Qt
QtWS25 Last Chance

Resources files in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by A Former User
    #1

    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!

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      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.

      RIVOPICOR 1 Reply Last reply
      3
      • ? A Former User

        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.

        RIVOPICOR Offline
        RIVOPICOR Offline
        RIVOPICO
        wrote on last edited by RIVOPICO
        #3

        @Wieland Ok i will check. One thing rc files in qt are not used?. I think rc files can be included in the project. I will check the way with Qt.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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).

          1 Reply Last reply
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved