Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[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?



  • You can use QuaZIP. It's a wrapper for zlib.



  • There is a FAQ entry on compression and decompression.



  • 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@
    :(



  • 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.



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



  • 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.



  • You're welcome. You might try

    @
    QDomDocument dom;
    dom.setContent(&proc);
    @

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



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



  • 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.


Log in to reply