Results 1 to 11 of 11

Thread: open/write gzipped file

  1. #1
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question open/write gzipped file

    Hello,

    I have gziped xml-files that are gziped. I can unzip then with gunzip on the commandline.
    how can I open such a file in Qt?

    there exists qCompress/qUncompress but this doesn't seem to work on .gz files.

    I also found this: http://quazip.sourceforge.net/

    ... is there a simpler way that doens't need an extra dependendency?
    (i don't need to write full zip-archives with multiple files etc.)

    thanks,
    niko

  2. #2
    Join Date
    Dec 2006
    Location
    Kędzierzyn-Koźle
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    Maybe http://osdab.sourceforge.net/ will be more helpful ??

  3. #3
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    thanks,

    but it looks like another full-blown-zip-archive library - I need only gzipping one file (something more lightweight)

    niko

  4. #4
    Join Date
    Dec 2006
    Location
    Kędzierzyn-Koźle
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    So maybe using QProcess and gzip would be more suitable?

  5. #5
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    that would be the easiest i guess...
    but would work only on unix

    or does something comparable exist on win32?

  6. #6
    Join Date
    Dec 2006
    Location
    Kędzierzyn-Koźle
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    Yes, you might use gzip from Cygwin ... I guess ..

  7. #7
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    sure, that will work

    but the users of my application won't be happy about that

  8. #8
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: open/write gzipped file

    zlib is fairly lightweight, you may want to try it. http://www.zlib.net/. This is the same compression library that Qt uses, but it doesn't expose the gzip functionality.

  9. #9
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    i was thinking about that too.
    but where to start?
    could you give me some hints?

    (i have almost no c++ experience)

    thanks
    niko

  10. #10
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: open/write gzipped file

    zlib is C, not C++. I have never used it directly. My first step would be to read its documentation and look at any example programs. You may also want to look at the qCompress sources to see how Trolltech uses it.

  11. #11
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: open/write gzipped file

    hooray, it works

    this is how I did it:
    Qt Code:
    1. gzFile file;
    2. file = gzopen (fileName.toUtf8().data(), "rb");
    3. if(!file) {
    4. QMessageBox::critical(0, tr("import"), tr("Can't open file"));
    5. return;
    6. }
    7. QByteArray input;
    8. char buffer[1024];
    9. QByteArray inputData;
    10. while(int readBytes = gzread (file, buffer, 1024))
    11. {
    12. input.append(QByteArray(buffer, readBytes));
    13. }
    14. gzclose(file);
    To copy to clipboard, switch view to plain text mode 

    thanks for the help....

    niko

Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  2. How To Extract A File
    By deekayt in forum General Programming
    Replies: 7
    Last Post: 5th December 2006, 18:27
  3. Qt 3.3.4 -> Qt 4.1.2, moc file issue
    By philski in forum Qt Tools
    Replies: 1
    Last Post: 11th September 2006, 21:08
  4. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 19:24
  5. File permission QFile::WriteOther on Win Dos
    By patrik08 in forum Newbie
    Replies: 1
    Last Post: 13th June 2006, 14:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.