PDA

View Full Version : rcc question



mojo2000
18th November 2009, 18:56
Hi,

I use rcc to get a all-in-one exe, with all scripts, pixmaps embeded.
It's exactly what I need for the customer part, but.....
When developing, it's a pain since I need to recompile every time I change a script.

Is there a way to switch from embeded to non embeded ?

Should I forget rcc and use another tool ?

Thanks

wysota
18th November 2009, 19:03
What exactly would you like to do? Keep the images in the filesystem and only build using resources when you have finished developing your application? If so then a simple solution would be to do it like this:


#ifdef WITH_RESOURCES
static QString pixmapPrefix=":";
#else
static QString pixmapPrefix="/complete/path/to/your/images/directory";
#endif
All you need to do then is to use pixmapPrefix to refer to the images.

QPixmap px(pixmapPrefix+"/images/myimage.png");
If you export this variable to scripts, you can use the same trick there.

A more elegant but requiring more work solution is to register your own prefix with QAbstractFileEngine that will either use resources or real files.

mojo2000
18th November 2009, 19:22
Hi,

Thanks very much for response.
Your solution solve 90 % my problem...

But 10% are missing....
I have a lots of libraries organized inside folders.
Related scripts, pixmaps are stored inside theses folders. Your solution works but only if I release all theses folders.
I used to work with freelance designers and with your solution I have to find a way to copy all theses folders (without any source code or privates things) and send them with the exe.
I think about a script to parse all qrc file and copy data's to the "pixmapPrefix" folder.

Is there another clever solution ?

Thanks

wysota
18th November 2009, 19:56
I used to work with freelance designers and with your solution I have to find a way to copy all theses folders (without any source code or privates things) and send them with the exe.
You can embed them into the binary and use resources, I don't see a problem. From what I understood the problem was you didn't want the files embedded into the binary while developing the application.

Did I understand you incorrectly?

mojo2000
18th November 2009, 20:26
Ah yes sorry.
Freelance designer used to edit pixmaps then restart the application to check the result.
Thats why I need to give them all pixmaps to re-design with the exe.

wysota
18th November 2009, 20:29
But what is the problem with my solution then? You can embed the data in the application if you want it or not embed it in the application if you want it. You can even have a solution that first you check if a file exists in the file system and if not, only then access the resources (you'd need your own file engine to do that smoothly).

mojo2000
18th November 2009, 20:46
I explained that your solution implies I give all my project tree (since pixmaps are stored in all projects subdirectory) and I cannot just zip my projects tree, I have first to remove all sensible files like sources, scripts, 3rd party licenses ect...

That why I'm thinking about a script that parse all qrc in all subdirectoies and copy all referenced file to another directory, zip this directory + exe then ship to the designer.
With this "solution" I'm sure I release all necessary files, and nothing else.

wysota
18th November 2009, 20:59
I explained that your solution implies I give all my project tree (since pixmaps are stored in all projects subdirectory) and I cannot just zip my projects tree, I have first to remove all sensible files like sources, scripts, 3rd party licenses ect..

I don't think my solution implies anything. Maybe I just didn't understand what you want. I still don't.

mojo2000
18th November 2009, 21:15
My project source tree:

ApplicationA
|-Bin
| |main.exe
|---Src
| |---Main
| |main.qrc
| |-----Png
| |------icon1.png
| |------icon2.png
| |------icon3.png
|-----Network
| |network.qrc
| |-----Png
| |------icon1.png
| |------icon2.png
| |------icon3.png
|-----Gui
| |gui.qrc
| |-----Png
| |------icon1.png
| |------icon2.png
| |------icon3.png
|-----Crypto
|crypto.qrc
|-----Png
|------icon1.png
|------icon2.png
|------icon3.png

inside main.qrc:

<RCC>
<qresource prefix="/main" >
<file>png/icon1.png</file>
<file>png/icon2.png</file>
<file>png/icon3.png</file>
</qresource>
</RCC>


To load the pixmap in main.cpp:
QPixmap(":/main/png/icon1.pmg")

Your solution means ":" -> "ApplicationA"
Then to load the icon:
QPixmap("ApplicationA/main/png/icon1.png")

It implies I have to release exactly my project tree + png, but without the rest.

wysota
18th November 2009, 21:19
If you keep the files as a resource in your binary, you just have to release the binary. Isn't that what you wanted? To have two solutions - one for customers, one for developers?

squidge
18th November 2009, 21:23
I think he wants three. One for customers, one for developers, and one for the graphics artists. 1st wants all embedded, 2nd wants everything external, and 3rd wants everything external but with all private files removed.

Maybe the best bet is a directory "rsrc" which all your resources are contained within, then you just copy this directory for 3, or copy everything for 2, and copy nothing for 1.

mojo2000
18th November 2009, 21:45
I think he wants three. One for customers, one for developers, and one for the graphics artists. 1st wants all embedded, 2nd wants everything external, and 3rd wants everything external but with all private files removed.

Exactly but in fact 2) is not required since 3) solve the problem for developer and external freelance designer.



Maybe the best bet is a directory "rsrc" which all your resources are contained within, then you just copy this directory for 3, or copy everything for 2, and copy nothing for 1.

That why I will try to make a script that parse all qrc files, then copy referenced files inside a "rsrc" directory.

Then for external designer, I just have to launch my script, all resources are then copied to "rsrc" and change ":" by "rsrc/" when loading pixmap.

This workflow solve my problem but with a script....

wysota
18th November 2009, 22:13
Write yourself an install script for qmake.

mojo2000
18th November 2009, 22:26
Problem solved !

I've created a script that search all qrc, then parse them and copy all references files to rsrc directory.
After that, I have all my resources files inside a common directory rsrc.

In my application, I have to use QAbstractFileEngineHandler + QAbstractFileEngine to handle filenames starting with ":" and just load files from rsrc directory.

To deactivate this feature, I just have to comment out the QAbstractFileEngineHandler.

youhou! No lines from my source code need to be changed !

Thank you for your help!