Results 1 to 7 of 7

Thread: Zipping a .txt file in Qt

  1. #1
    Join Date
    Mar 2011
    Location
    Mikkeli, Finland
    Posts
    8
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Zipping a .txt file in Qt

    Hi there,

    I have a simple application in Qt where the user enters data in a text file, which is then saved on desktop. After that I would like to be able to insert the .txt file in a .zip file.

    I have tried to use QuaZIP with no success, it seems too complicated to understand.

    Any help or suggestion would be greatly appreciated.

    Thank you in advance.

    Kind Regards,

    croussou
    Regards,

    croussou

  2. #2
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Zipping a .txt file in Qt

    didn't know about this wrapper, but you can directly use zip.h in minizip from zlib
    it s not that hard and there's is exemples that you can use

  3. #3
    Join Date
    Mar 2011
    Location
    Mikkeli, Finland
    Posts
    8
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: Zipping a .txt file in Qt

    Thank you for replying.

    Any available examples that you can share?
    Regards,

    croussou

  4. #4
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Zipping a .txt file in Qt

    here is the api web page:
    http://www.winimage.com/zLibDll/minizip.html

    and you can find an example of an email writter that use zip for the attached files:
    http://www.winimage.com/zLibDll/mapi...mo_gooddll.zip

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Zipping a .txt file in Qt

    We are using QuaZIP. What is a real problem ?

  6. #6
    Join Date
    Mar 2011
    Location
    Mikkeli, Finland
    Posts
    8
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: Zipping a .txt file in Qt

    Can you please give an example zipping a simple text file using QuaZIP?
    Regards,

    croussou

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Zipping a .txt file in Qt

    This method packs list of files :
    Qt Code:
    1. bool MyPacker::packFiles( QString zip_name, QFileInfoList files )
    2. {
    3. QuaZip( zip_name );
    4. zip.setFileNameCodec("Windows-1250");
    5. if( !zip.open( QuaZip::mdCreate ) )
    6. {
    7. return QString();
    8. }
    9.  
    10. QFile inFile;
    11. QuaZipFile outFile(&zip);
    12.  
    13. char c;
    14. int j = 0;
    15.  
    16. foreach(QFileInfo fileInfo, files)
    17. {
    18. if (!fileInfo.isFile())
    19. continue;
    20.  
    21. inFile.setFileName( fileInfo.absoluteFilePath() );
    22.  
    23. if (!inFile.open(QIODevice::ReadOnly))
    24. {
    25. return QString();
    26. }
    27.  
    28. if (!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileInfo.fileName(), fileInfo.filePath())))
    29. {
    30. return QString();
    31. }
    32.  
    33. while (inFile.getChar(&c) )
    34. outFile.putChar(c));
    35.  
    36. if (outFile.getZipError() != ZIP_OK)
    37. {
    38. return false;
    39. }
    40.  
    41. outFile.close();
    42.  
    43. if (outFile.getZipError() != ZIP_OK)
    44. {
    45. return false;
    46. }
    47.  
    48. inFile.close();
    49. }
    50.  
    51. zip.close();
    52.  
    53. if (zip.getZipError() != 0)
    54. {
    55. return false;
    56. }
    57.  
    58. return true;
    59. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 3
    Last Post: 1st November 2010, 16:33
  2. Replies: 4
    Last Post: 9th May 2010, 16:18
  3. Replies: 3
    Last Post: 28th March 2009, 15:37
  4. Replies: 0
    Last Post: 6th March 2009, 08:19
  5. Replies: 3
    Last Post: 25th May 2007, 07:49

Tags for this Thread

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.