October 31, 2011

RazrFalcon RazrFalcon
Lab Rat
114 posts

[SOLVED] How to get text of svgz file?

 

I need to add svgz(zipped svg) content to the QDomDocument.
Usual svg i can open with QFile & QTextStream.

Only way I find, is to extract it with gunzip. But then I must to use additional qprocess.

Is there any other way?

 Signature 

QT != Qt
Gentoo + KDE

9 replies

November 1, 2011

p-himik p-himik
Lab Rat
262 posts

You can use QuaZIP. It’s a wrapper for zlib.

November 1, 2011

Andre Andre
Area 51 Engineer
6077 posts

There is a FAQ entry on compression and decompression.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

November 1, 2011

RazrFalcon RazrFalcon
Lab Rat
114 posts

I can’t uncompress svgz with quazip or qzipreader.
I can uncompress only usual zip files.

Only way I find, is to rename svgz to gz.
And then:

  1. gunzip vector.gz

:(

 Signature 

QT != Qt
Gentoo + KDE

November 1, 2011

Volker Volker
Robot Herder
5428 posts

You can start a QProcess using “gunzip -c”, then feed the compressed svgz to the process’ stdin (using QProcess::write!) and read the decompressed data from the process’ stdout (using QProcess::read!). As QProcess is a QIODevice, you might try to attach a QTextStream to it for reading.

November 1, 2011

RazrFalcon RazrFalcon
Lab Rat
114 posts

:)
So, Qt can’t read svgz.
I’ll try to use method proposed by Volker.
Thanks.

 Signature 

QT != Qt
Gentoo + KDE

November 1, 2011

RazrFalcon RazrFalcon
Lab Rat
114 posts

It was easier than I thought:

  1. QProcess proc(this);
  2. args<<"-c"<<"../vector.svgz";
  3. proc.start("gunzip",args);
  4. proc.waitForFinished();
  5. qDebug()<<proc.readAll();

At the output I get svg text.
Then I replace qDebug with it:
  1. dom.setContent(proc.readAll());

And my problem is solved!
Thanks Volker again.

 Signature 

QT != Qt
Gentoo + KDE

November 1, 2011

Volker Volker
Robot Herder
5428 posts

You’re welcome. You might try

  1. dom.setContent(&proc);

Maybe that saves you from copying around some bytes in the QByteArray.

November 1, 2011

RazrFalcon RazrFalcon
Lab Rat
114 posts

Thanks a lot. Again. :)
I didn’t know about this method.

 Signature 

QT != Qt
Gentoo + KDE

November 1, 2011

Volker Volker
Robot Herder
5428 posts

In Qt, many classes that deal with data have a constructor or method that uses a QIODevice pointer as data source. It’s always worth a try to look for those.

 
  ‹‹ MacOS override cmd+space shortcut      qgraphicsview can’t preview by QPrintPreviewDialog ››

You must log in to post a reply. Not a member yet? Register here!