Important: Please read the Qt Code of Conduct -

How to use QuaZIP for zipping a file

  • I am currently using a simple code for generating a .zip file containing a .txt file.

    @QCoreApplication a(argc, argv);

    QFile input("/Users/croussou_dm4/Desktop/text1.txt");
    QFile output("/Users/croussou_dm4/Desktop/");;;
    QByteArray uncompressedData = input.readAll();
    QByteArray compressedData = qCompress(uncompressedData);
    return a.exec();@

    I have read and tested that the file cannot be opened with any unzipping program because it is missing relevant header information as well as the "magic number" (explain?). Several sources indicate that QuaZIP seems to do the work, but I don't understand exactly how to use it...

    Any ideas and suggestions would be greatly appreciated.

    Thank you in advance.

  • A compressed file, an archive and a .zip file are three different things:

    • a compressed file is a plain file converted into a different format with a lesser size,
    • an archive is a set of uncompressed files packed in a single uncompressed file,
    • a .zip file is a compressed archive, using a specific archive and compression format.

    You cannot create one and treat it as another.

    QuaZip allows you to handle .zip files. It is documented and comes with some examples. In addition, there are multiple threads on the forums on QuaZip.

    Is there a specific problem you've encountered?

  • Thank you for your prompt reply.

    I am just searching for a solid, simple example to start. Because at the moment I have only an abstract idea what I can achieve with QuaZIP. I just want to save a .txt file in a .zip, nothing else.

Log in to reply