Results 1 to 8 of 8

Thread: Open zip with QuaZip from Qbuffer variable

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Open zip with QuaZip from Qbuffer variable

    Hi! I'm trying to open a zip file that is inside a reply from my server.
    I have that zip inside a QBuffer and I'm trying to open it with QuaZip, but it's not working...
    I want to do something like this:

    QByteArray msg = reply->readAll();
    QBuffer buffer(&msg);
    buffer.open(QIODevice::WriteOnly);
    buffer.write(msg.data(), msg.size());
    buffer.seek(3);
    buffer.close();
    QString json_var = extractAll_fomVar(&buffer);

    I can unzip a file in disk but I don't want to create that file... I want to use it in memory...

    I have this error:
    QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode
    Invalid JSON...

    How can I do that?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Open zip with QuaZip from Qbuffer variable

    Why are you writing into the buffer?

    I would have expected that you just open it for reading and pass the pointer to the extractAll_fomVar() function.

    Right now you are overwriting the data with itself and then handing a closed buffer to your function.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    vitor13almeida (26th September 2016)

  4. #3
    Join Date
    Sep 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: Open zip with QuaZip from Qbuffer variable

    To create a QuaZip var I can use the path to my zip file or a QIODevice var...
    So I wrote my data from QBytesArray to a QBuffer var.
    Inside extractAll_fomVar() I open buffer for reading

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Open zip with QuaZip from Qbuffer variable

    Aside from your unnecessary writing of the same data again, does it work if you save the "msg" into a file and pass an unopened QFile to that?

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    vitor13almeida (26th September 2016)

Similar Threads

  1. Can't open password protected zip file using QuaZip
    By Rajesh.Rathod in forum Qt Programming
    Replies: 9
    Last Post: 14th October 2016, 13:09
  2. Unable to open zipped file which is zipped with Quazip
    By zgulser in forum Qt Programming
    Replies: 0
    Last Post: 12th October 2012, 18:14
  3. Size Of QBuffer Not Correct?
    By justin123 in forum Qt Programming
    Replies: 2
    Last Post: 20th April 2011, 02:10
  4. QBuffer::readLine()
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2010, 20:57
  5. QBuffer bytesWritten() problem
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 09:05

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
  •  
Qt is a trademark of The Qt Company.