QtSvgzPlugin - compressed SVGs for the Qt4 icon engine

Qt 4.5 adds native support for compressed SVGs so this plugin makes only sense for earlier releases.


QtSvgzPlugin is a plugin that adds support for gzip compressed SVG files (a.k.a. .svgz files) to Qt's icon engine.

The library is a regular QIconEngine plugin and is mostly based on the QSvgIconEnginePlugin class found in Qt 4.2 or later. Let's say that 90% of the code is the same as QSvgIconEnginePlugin ;-)

A feature request has been sent to the trolls and they are taking it into account, so it's highly probable that you will see support for svgz files in some next minor version of Qt.

The plugin uses zlib for actual decompression but you don't even need to have the library, as Qt is statically linked to zlib. You will only need two zlib header files to build the plugin!

The package contains a cool example application so you can see how easy it is to use compressed svg icons with this plugin. Everything is transparent, just create a QIcon object as you always do.

Qt's Resource System is also supported so you can embed your icons with no worries.

Using the plugin is quite easy. If you don't want to look at the example application, just remember these few steps:

  1. Link your application against the plugin (it's a static library)
  2. Link your application against the QtSvg module
  3. Add the Q_IMPORT_PLUGIN(QtSvgzIconEnginePlugin) macro somewhere (possibly in main.cpp)
  4. Run inkscape and draw some great scalable icons or call your favorite designer
  5. Shut down the pc and have a life ;-)

And thanks for all the fish

First off, any comment, suggestion, bug report is welcome. I have written the plugin in about ten minutes so don't expect it to be the state of the art :D

The example application is based on the "icons" example shipped with Qt 4, so thanks again to the trolls. Again, I want to remember that my contribute was quite minimal. I just took a couple of code lines from my unzip classes, changed a couple of things to make everything work with gzip stream and that's all. Most of the work has been done by the trolls and by the zlib developers. Thank you guys :D




Missing features and restrictions

Usage example

Always refer to the example application's main.cpp file or to the class comments in the source files for details and more (and updated) usage examples.

// ...in some mysterious main.cpp file:
#include <qtsvgz_plugin.h>
// Don't forget to add the next line or to link both the plugin and QtSvg!
// Well, that's all. Nothing else to do to enable svgz support:
QAction* fileNewAct = new QAction(QIcon(":/images/document_new.svgz"), tr("New random document"), this);

The applications .pro file:

// ... INCLUDEPATH += path/to/qt/svgz/plugin/includes // Remember to link both the Qt SVG module and the plugin QT += svg LIBS += -Lpath/to/qt/svgz/plugin/lib -lQtSvgzPlugin // ...

Technical details

zlib linking

Linking the zlib library is not really required as it is statically linked into the Qt libraries. Qt's QtCore library exports all the zlib functions, so you only need to let your INCLUDEPATH point to the zlib.h and zconf.h header files. Anyway, if you want to use a specific version of the zlib library you will need to link against it as usual.

A task has been opened on Trolltech's Task Tracker to add svgz support to Qt. I suppose it's mainly a matter of finding an hour of free time and see if there are any binary compatibility issues. Check out the tracker entry #192203.