Originally Posted by
pratik041
Have you ever used .rc file in vc++.
Yes.
I want to make resources file something like that. Storing macro in .rc file and accessing it in program wherever used.
You can, of course, use the Windows resource system on Windows.
It's not clear what macros you are referring to. The macros that are associated with a Windows rc files are defined outside the rc file in a header file. Your C++ source code uses that header file to access those macro definitions. When you use those macros in conjunction with the Win32 API function that load reosurces, e.g. LoadCursor(), the Windows library fetch the relevant blob of the (compiled) resource data and return it. For example:
// In resources.h
#define IDC_TARGET 1000
// In resources.rc
#include "resources.h"
IDC_TARGET CURSOR "Target.cur"
// In some cpp file
#include "resources.h"
...
LoadCursor(NULL, IDC_TARGET);
// In resources.h
#define IDC_TARGET 1000
// In resources.rc
#include "resources.h"
IDC_TARGET CURSOR "Target.cur"
// In some cpp file
#include "resources.h"
...
LoadCursor(NULL, IDC_TARGET);
To copy to clipboard, switch view to plain text mode
Nothing is stopping you from doing something similar for a Qt resource file:
// In resources.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/target.png>
</qresource>
</RCC>
// In resources.h
#define IDC_TARGET ":/icons/target.png"
// In some cpp file
#include "resource.h"
...
// In resources.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/target.png>
</qresource>
</RCC>
// In resources.h
#define IDC_TARGET ":/icons/target.png"
// In some cpp file
#include "resource.h"
...
QCursor cursor(QPixmap(IDC_TARGET));
To copy to clipboard, switch view to plain text mode
or you can use the alias mechanism in the QRC file to provide a name that is independent of the included file name (so you can change the underlying file without changing your code):
// In resources.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="IDC_TARGET">icons/target.png>
</qresource>
</RCC>
// In some cpp file
// In resources.qrc
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="IDC_TARGET">icons/target.png>
</qresource>
</RCC>
// In some cpp file
QCursor cursor(QPixmap(":/IDC_TARGET"));
To copy to clipboard, switch view to plain text mode
Bookmarks