PDA

View Full Version : How can we create external Binary Resources in qt ?



pratik041
1st December 2011, 05:06
what is the format to create it? Does we can make custom resources with it?

pratik041
1st December 2011, 05:18
what is the format to create it? Does we can make custom resources with it?

ChrisW67
1st December 2011, 05:51
Do not cross post the same question in multiple places: that is bad form.
See: How can we create external Binary Resources in qt

Comment: This post was originally on a different thread before I merged both. Thus the post looks misplaces now... (Lykurg)

ChrisW67
1st December 2011, 05:53
It is in the friendly manual under The Qt Resource System

pratik041
1st December 2011, 06:21
It is in the friendly manual under The Qt Resource System
i think you are talking about storing images only i want to store widget geometry, style and i want to access it when required. Do you know how can we do it?

ChrisW67
1st December 2011, 06:34
A typical use of the resource system is to store images but you can store any data you like in the resource and interpret it any way you like when you read it. Resources are read only, so if the problem you are trying solve involves saving settings between runs then you want QSettings or your own file format, which has nothing to do with resources.

pratik041
1st December 2011, 07:23
A typical use of the resource system is to store images but you can store any data you like in the resource and interpret it any way you like when you read it. Resources are read only, so if the problem you are trying solve involves saving settings between runs then you want QSettings or your own file format, which has nothing to do with resources.
Have you ever used .rc file in vc++. I want to make resources file something like that. Storing macro in .rc file and accessing it in program wherever used.

ChrisW67
1st December 2011, 22:45
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);


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"
...
QCursor cursor(QPixmap(IDC_TARGET));

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
QCursor cursor(QPixmap(":/IDC_TARGET"));

pratik041
2nd December 2011, 07:01
Yes.

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


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"
...
QCursor cursor(QPixmap(IDC_TARGET));

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
QCursor cursor(QPixmap(":/IDC_TARGET"));


Thank you it is now little bit clear but you are storing only image in qrc file. Can we store buttontext, style, location of widget in qrc file. If yes how we will write that ?