Results 1 to 9 of 9

Thread: A problem regarding QuaZip

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default A problem regarding QuaZip

    Hi,

    I'm using QuaZip to archive my files like the following;

    Qt Code:
    1. QByteArray LoggerManager::packFiles(const QString& p_name, const QByteArray& p_BytesToBrCompressed)
    2. {
    3. QString testZip = p_name;
    4. QuaZip zip(testZip);
    5.  
    6. zip.setFileNameCodec("IBM866"); /* or Windows-1250 */
    7.  
    8. if(!zip.open(QuaZip::mdCreate))
    9. {
    10. qWarning("testCreate(): zip.open(): %d", zip.getZipError());
    11. return NULL;
    12. }
    13.  
    14. QString loc = qApp->applicationDirPath() + "/logs/error_log/";
    15.  
    16. QFileInfoList files=QDir(loc).entryInfoList();
    17. QFile inFile;
    18. QFile inFileTmp;
    19. QuaZipFile outFile(&zip);
    20. char c;
    21. QByteArray compressedData = "";
    22.  
    23. foreach(QFileInfo file, files)
    24. {
    25. if(!file.isFile())
    26. continue;
    27.  
    28. inFileTmp.setFileName(file.fileName());
    29. inFile.setFileName(file.filePath());
    30.  
    31. if(!inFile.open(QIODevice::ReadOnly))
    32. {
    33. qWarning("testCreate(): inFile.open(): %s", inFile.errorString().toLocal8Bit().constData());
    34. return NULL;
    35. }
    36.  
    37. if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(inFileTmp.fileName(), inFile.fileName())))
    38. {
    39.  
    40. qWarning("testCreate(): outFile.open(): %d", outFile.getZipError());
    41. return NULL;
    42. }
    43.  
    44. while(inFile.getChar(&c)&&outFile.putChar(c));
    45.  
    46. if(outFile.getZipError()!=UNZ_OK)
    47. {
    48. qWarning("testCreate(): outFile.putChar(): %d", outFile.getZipError());
    49. return NULL;
    50. }
    51.  
    52. compressedData = outFile.readAll();
    53.  
    54. outFile.close();
    55.  
    56. if(outFile.getZipError()!=UNZ_OK)
    57. {
    58. qWarning("testCreate(): outFile.close(): %d", outFile.getZipError());
    59. return NULL;
    60. }
    61.  
    62. inFile.close();
    63. }
    64.  
    65. zip.close();
    66.  
    67. if(zip.getZipError()!=0)
    68. {
    69. qWarning("testCreate(): zip.close(): %d", zip.getZipError());
    70. return NULL;
    71. }
    72.  
    73. return compressedData;
    74. }
    To copy to clipboard, switch view to plain text mode 

    The problem is; I want to send this zipped content to an HTTP server. But

    Qt Code:
    1. compressedData = outFile.readAll();
    To copy to clipboard, switch view to plain text mode 

    is non-sense since outFile is writeOnly which makes compressedData empty string.

    I try the following to overcome this situation;

    Qt Code:
    1. QFile reader(p_name);
    2. if(QFile::exists(reader.fileName()))
    3. {
    4. if(reader.open(QIODevice::ReadOnly))
    5. {
    6. compressedData.append(reader.readAll());
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    But it didn't work either..

    Any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A problem regarding QuaZip

    Does the server support only HTTP? FTP would be better.

    Is the archive read-only file (in the file system) or do you mean its only the attribute with which you open the QFile object, but the file it self is not read-only?
    But it didn't work either..
    By "not working" do you mean compressData is empty?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: A problem regarding QuaZip

    Does the server support only HTTP? FTP would be better.
    Yepp!

    Is the archive read-only file (in the file system) or do you mean its only the attribute with which you open the QFile object, but the file it self is not read-only?
    arcihive is opened write-only by default. That's why I can't read it. And I opened QFile object ad read-only by myself.

    By "not working" do you mean compressData is empty?
    Sorry..Yes.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A problem regarding QuaZip

    and you are sure (by means of stepping trough or debug message) that:
    compressedData.append(reader.readAll());
    is being called?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: A problem regarding QuaZip

    Yeah, definitely...

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: A problem regarding QuaZip

    What is the size of the file when you look it up with a file manager?
    What is the size of the file when you do reader.size()?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: A problem regarding QuaZip

    it's size seems completely logical to me. About 20000 bytes.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A problem regarding QuaZip

    And you can't reopen it in read only mode after you're done creating the archive?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: A problem regarding QuaZip

    Hi,

    I'm very sorry to take your time but my problem caused by VS 2010 debugger. I was actually reading the file contents properly but the debugger doesn't show me. When I did qDebug, I saw all the contents of the file that i'm reading.

    thanks for your care.

Similar Threads

  1. Quazip Installation Issues
    By frankiefrank in forum Newbie
    Replies: 8
    Last Post: 22nd April 2011, 09:45
  2. QuaZIP and Password?
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2008, 09:10
  3. QuaZip + dir inside
    By Axsis in forum Newbie
    Replies: 0
    Last Post: 7th May 2008, 12:28
  4. [Solved] QuaZIP and getting a file out of an archiv
    By Lykurg in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2008, 07:44

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.