[SOLVED] How to get text of svgz file?
-
wrote on 31 Oct 2011, 21:06 last edited by
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?
-
wrote on 1 Nov 2011, 02:31 last edited by
You can use QuaZIP. It's a wrapper for zlib.
-
wrote on 1 Nov 2011, 07:25 last edited by
There is a FAQ entry on compression and decompression.
-
wrote on 1 Nov 2011, 11:54 last edited by
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:
@gunzip vector.gz@
:( -
wrote on 1 Nov 2011, 12:20 last edited by
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.
-
wrote on 1 Nov 2011, 13:03 last edited by
:)
So, Qt can't read svgz.
I'll try to use method proposed by Volker.
Thanks. -
wrote on 1 Nov 2011, 13:20 last edited by
It was easier than I thought:
@QProcess proc(this);
QStringList args;
args<<"-c"<<"../vector.svgz";
proc.start("gunzip",args);
proc.waitForFinished();
qDebug()<<proc.readAll();@
At the output I get svg text.
Then I replace qDebug with it:
@QDomDocument dom;
dom.setContent(proc.readAll());@
And my problem is solved!
Thanks Volker again. -
wrote on 1 Nov 2011, 17:18 last edited by
You're welcome. You might try
@
QDomDocument dom;
dom.setContent(&proc);
@Maybe that saves you from copying around some bytes in the QByteArray.
-
wrote on 1 Nov 2011, 17:57 last edited by
Thanks a lot. Again. :)
I didn't know about this method. -
wrote on 1 Nov 2011, 18:16 last edited by
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.
4/10