Import-Export-resources-for-setup-creation

From Qt Wiki
Revision as of 15:57, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Import & Export of resources for creating a setup (windows)

Introduction

For almost every finished Qt project it is wanted and in most cases also required to carry extern resources.
When porting the executable to other users on other computers that usually don’t have Qt installed, it is necessary to port the needed Qt libraries, too.
Also, it is often necessary to include sound files, pictures, text files and other stuff to the executable.
One common way is to pack all that stuff into a zip archive and hope that the target user will manage things correctly.
Another, more complicated and maybe not in every case usable way would be to use the Qt resource management.

For those of you who would like to handle import/export of every kind of resource very easily, I wrote a little “ResourceManager”.

Headers & Source files

The obligatory algorithms are stored in two files:
1. resourcemanager.h
2. resourcemanager.cpp

For easy creating a setup file by mouse clicking, I also wrote a user interface. This interface additionally requires the following six files:
1. mainwindow.h
2. mainwindow.cpp
3. myQDialogGetFile.h
4. myQDialogGetFile.cpp
5. myQDialogGetNewFile.h
6. myQDialogGetNewFile.cpp

Implementation

Basic usage without user interface (not advisable!)

For basic usage of the ResourceManager, you have to create a new project (this will be the executable that will import the resources to your setup) and add the two obligatory files (resourcemanager.h, resourcemanager.cpp).
In the main source file, you only have to specify the resources and pass them to the resourcemanager algorithm.
There are two functions that can be used, depending on how the resources shall be passed:
a) as a QStringList:

b) from an existing resource table file (ini format):
ResourceTable.ini:

I strongly recommend not to call the resourcemanager algorithms manually, because there are lots of mistakes that can happen like typing a wrong resource path, using forbidden characters (e.g.g backslash) and so on.
It is advisable to use the user interface instead.

Using graphical user interface

For using the interface, you only have to create a new project and import all files given above (resourcemanager.h/.cpp, mainwindow.h/.cpp, myQDialogGetFile.h/.cpp, myQDialogGetNewFile.h/.cpp), compile and run it.
After the mainwindow is shown, you can select new resources from your computer and add them to the resource table, or you can load an already existing resource table (ini file). By clicking the button “import to library” you can import all files from the table to your specified setup file.
You can also save the chosen resources as a new resource table file for later use.

Exporting resources on clients computer

The only thing you have to modify in your setup file project is to add the two resourcemanager files (resourcemanager.h/.cpp) and place the following command into the main function (or anywhere else at the point of execution where resources should be exported):
The path you have to pass to the ResourceManager is the path of the setup file itsself, because there are the resources stored.

Files

resourcemanager.h

resourcemanager.cpp

mainwindow.h

mainwindow.cpp

myQDialogGetFile.h

myQDialogGetFile.cpp

myQDialogGetNewFile.h

myQDialogGetNewFile.cpp

Feedback

I would really appreciate it to get some feedback from you, so I can improve my own skills and make the algorithms better.

Thank you in anticipation!