Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41

Thread: how to unzip the file in qt using gzip

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

    Default Re: how to unzip the file in qt using gzip

    How do you expect and output when the process has not run when you try to read the output?
    There is no time machine in QProcess, it can only deliver output when the program it runs has written some.

    A program needs to run in order to generate output.

    Also, program refers to, well a program.
    Your "program" variable has way more than just the program.
    Maybe you should consult a dictionary between English and your native language on "program" and "argument"

    Btw, why is your ZIP file again compressed?

    Cheers,
    _

  2. #22
    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: how to unzip the file in qt using gzip

    QProcess::start only starts the process - don't wait for finish.

  3. #23
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    thanks i will try to improve ..can you please give some examples for Qprocess in start,finished,error..

  4. #24
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to unzip the file in qt using gzip

    Quote Originally Posted by Radek View Post
    Try unzip instead of "gunzip". "gunzip" is, most likely, a Gnome utility (guessing from the prefix "g").
    The OP said he needed to uncompress a file using gzip. The counterpart of gzip is gunzip where the "g" stands for GNU and these are standard command line programs available for every OS.


    Added after 9 minutes:


    Quote Originally Posted by iswaryasenthilkumar View Post
    i wriiten code
    Qt Code:
    1. QString program="/home/digital_images/todaytomrowcheck";//this was my qt program path
    2. QStringList arguments;
    3. arguments<<" /home/digital_images/Desktop/zipfile.zip.gz"; // this was my zipfile path
    4. myProcess=new QProcess(this);
    5. myProcess->start(program,arguments);
    6. QByteArray result=myProcess->readAll();
    7. qDebug()<<result;
    To copy to clipboard, switch view to plain text mode 
    the program executed bt i dont get any result i get " " this output..actually i missing something i need after reading this zipfile i need to extract the zip file.. give some idea to implement
    Thanks in advance
    Perhaps I was not explicit enough in prior posts but the program variable needs to specify the binary executable you want to execute in a separate process with QProcess. Even more explicitly:

    Qt Code:
    1. QString program="gunzip";
    2. QStringList arguments;
    3. arguments << "/home/digital_images/Desktop/zipfile.zip.gz"; // this was my zipfile path (note that I removed the leading space you had coded)
    To copy to clipboard, switch view to plain text mode 

    If gunzip isn't in your path in a standard location like /usr/bin, then you will need to specify the full path to the gunzip executable or modify the PATH environmental variable used by QProcess, but that is a more advanced step and I'm not going to go there now until you comprehend the basics for QProcess.

    Go to your terminal and type the command "which gunzip". If it is found in your path statement, the fully qualified path will be shown. If it is not found, then you don't have gzip/gunzip properly installed and will need to install the gzip/gunzip package for your OS.

    Edit: if QProcess proves to be too hard for you to implement, then you can go down the path others have identified by using a library to uncompress your file, but that will require a different set of skills and a slew of new challenges for you to implement.
    Last edited by jefftee; 24th March 2015 at 18:11.

  5. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (25th March 2015)

  6. #25
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    finally i got idea to implement how to use Qprocess bt i dont get proper result
    my code below
    Qt Code:
    1. QProcess OProcess;
    2. QString Command;
    3. Command = "bash -c \"gzip -c file1.doc > file1.zip\"";
    4. args<<"/home/digital_images";
    5. OProcess.start(Command,args,QIODevice::ReadOnly);
    6. OProcess.waitForFinished();
    7. QString StdOut = OProcess.readAllStandardOutput();
    8. QString StdError = OProcess.readAllStandardError();
    9. std::cout<<"\n Printing the standard output..........\n";
    10. std::cout<<endl<<StdOut.toStdString();
    11. std::cout<<"\n Printing the standard error..........\n";
    12. std::cout<<endl<<StdError.toStdString();
    To copy to clipboard, switch view to plain text mode 
    here my file was not converted to zip,,bt while terminal it was executing properly what am doing wrong here

  7. #26
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to unzip the file in qt using gzip

    Quote Originally Posted by iswaryasenthilkumar View Post
    finally i got idea to implement how to use Qprocess bt i dont get proper result
    Sorry to disagree, but it's obvious you still don't understand what you're doing...

    First off, are you trying to compress a file or uncompress a file? Your original post said you were trying to uncompress a file, but your [still] incorrect example, well, I'm no longer sure what you are trying to accomplish actually.

    Secondly, you don't need to execute the bash shell, so no clue why you have added that. Even if you wanted to execute bash, the program variable would be bash and everything after bash in your example would be arguments to the bash program.

    To be very clear, the program is the executable binary you are trying to execute and all of the arguments that need to be passed to that program need to be supplied as program arguments.

    Even then, the example you posted attempts to compress file1.doc, sending the output to stdout (gzip -c), which you then direct (>) to file file1.zip and then you are supplying what, a random directory for some unknown reason.

    I had already posted exactly what your program and program arguments variable should be. I don't know how to help you if you keep ignoring what I say and then you cobble together some incomprehensible code from what I can only imagine are the result of some mashup of different Google searches!

    Use the example I already posted and come back with actual results, return codes, etc or else I literally don't know how to help you.

    Edit: I hate myself for doing this , but here's a working example for what you're trying to accomplish:

    Qt Code:
    1. bool success;
    2. QProcess gunzip;
    3. gunzip.setProcessChannelMode(QProcess::MergedChannels);
    4. QString program = "gunzip";
    5. QStringList arguments = {"-v","/Users/jefft/test.dat.gz"};
    6. gunzip.start(program, arguments);
    7. success = gunzip.waitForStarted();
    8. if (!success)
    9. {
    10. qDebug("waitForStarted() error: %s", gunzip.errorString().toUtf8().constData());
    11. return;
    12. }
    13. success = gunzip.waitForFinished();
    14. if (!success)
    15. {
    16. qDebug("waitForFinished() error: %s", gunzip.errorString().toUtf8().constData());
    17. return;
    18. }
    19. QByteArray buffer = gunzip.readAll();
    20. QString output = buffer;
    21. qDebug("%s", output.toUtf8().constData());
    To copy to clipboard, switch view to plain text mode 

    The code above will uncompress file test.dat.gz and produces the following output, which you would want to parse to get the uncompressed file name:

    Qt Code:
    1. /Users/jefft/test.dat.gz: -99.9% -- replaced with /Users/jefft/test.dat
    To copy to clipboard, switch view to plain text mode 

    The code above uses QProcess::waitFor*, which I don't recommend because your GUI will hang. Not a big deal if your files are small, but uncompressing a large file would noticeably hang your GUI. Start with this and once you have working, replace with started() and finished() signals connected to slots in your program.
    Last edited by jefftee; 25th March 2015 at 07:00.

  8. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (25th March 2015)

  9. #27
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    sorry i forget to mention in last post i triying nw Qprocess concept .. first let me try to convert zip file tats y i tried that code..soryy if i hurted you jthomps..am very slow pick bt am sure i will reach my destiny i dnt know when.

  10. #28
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to unzip the file in qt using gzip

    You didn't hurted me, I'll be OK...

    If you want help in the future, you'll find that people are much more willing to help if you don't ignore what they suggest and come back with the same questions or a completely different code sample. i.e. If you are trying to solve a different problem than the one you state in your original post, then start a new thread.

    Hopefully you can take the example I gave you in my prior post and modify that to accomplish whatever it is now that you're trying to accomplish. It shows the proper way to use the program and program arguments passed to the program. It shows proper checking of return codes, etc.

    Good luck.

  11. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (25th March 2015)

  12. #29
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    AFAIK, gzip both compresses and uncompresses: "gzip -d file(s)". I haven't heard about "gunzip" so far but now I understand better The "gunzip" is needed because of "double zipping" .zip.gz Therefore:
    (1) first "ungz" by something, for example by "gzip"
    (2) then unzip by libkarchive (if you are using Qt5), libkdecore or "unzip"

    ... and do not "double zip". You cannot gain anything by the second zipping.

  13. #30
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    i used your code its working and it resolved my problem i have one more doubt,,nw i want to unzip the folder not file am having zip folder(folder1.zip).i have to unzip this folder i used with terminal command unzip folder1.zip by terminal its executing when am using in qt i getting error.the error below
    waitForFinished() error: Process operation timed out
    QProcess: Destroyed while process is still running.
    my code below
    Qt Code:
    1. QString program = "unzip";
    2. arguments<<"/home/digital_images/Desktop/folder1.zip";
    3. gunzip.start(program, arguments);
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by jthomps View Post
    Sorry to disagree, but it's obvious you still don't understand what you're doing...

    First off, are you trying to compress a file or uncompress a file? Your original post said you were trying to uncompress a file, but your [still] incorrect example, well, I'm no longer sure what you are trying to accomplish actually.

    Secondly, you don't need to execute the bash shell, so no clue why you have added that. Even if you wanted to execute bash, the program variable would be bash and everything after bash in your example would be arguments to the bash program.

    To be very clear, the program is the executable binary you are trying to execute and all of the arguments that need to be passed to that program need to be supplied as program arguments.

    Even then, the example you posted attempts to compress file1.doc, sending the output to stdout (gzip -c), which you then direct (>) to file file1.zip and then you are supplying what, a random directory for some unknown reason.

    I had already posted exactly what your program and program arguments variable should be. I don't know how to help you if you keep ignoring what I say and then you cobble together some incomprehensible code from what I can only imagine are the result of some mashup of different Google searches!

    Use the example I already posted and come back with actual results, return codes, etc or else I literally don't know how to help you.

    Edit: I hate myself for doing this , but here's a working example for what you're trying to accomplish:

    Qt Code:
    1. bool success;
    2. QProcess gunzip;
    3. gunzip.setProcessChannelMode(QProcess::MergedChannels);
    4. QString program = "gunzip";
    5. QStringList arguments = {"-v","/Users/jefft/test.dat.gz"};
    6. gunzip.start(program, arguments);
    7. success = gunzip.waitForStarted();
    8. if (!success)
    9. {
    10. qDebug("waitForStarted() error: %s", gunzip.errorString().toUtf8().constData());
    11. return;
    12. }
    13. success = gunzip.waitForFinished();
    14. if (!success)
    15. {
    16. qDebug("waitForFinished() error: %s", gunzip.errorString().toUtf8().constData());
    17. return;
    18. }
    19. QByteArray buffer = gunzip.readAll();
    20. QString output = buffer;
    21. qDebug("%s", output.toUtf8().constData());
    To copy to clipboard, switch view to plain text mode 

    The code above will uncompress file test.dat.gz and produces the following output, which you would want to parse to get the uncompressed file name:

    Qt Code:
    1. /Users/jefft/test.dat.gz: -99.9% -- replaced with /Users/jefft/test.dat
    To copy to clipboard, switch view to plain text mode 

    The code above uses QProcess::waitFor*, which I don't recommend because your GUI will hang. Not a big deal if your files are small, but uncompressing a large file would noticeably hang your GUI. Start with this and once you have working, replace with started() and finished() signals connected to slots in your program.

  14. #31
    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: how to unzip the file in qt using gzip

    Dear iswaryasenthilkumar read the documentation it does not hurt. Read about QProcess::waitForFinished and everything will be clear.

  15. The following user says thank you to Lesiok for this useful post:

    iswaryasenthilkumar (25th March 2015)

  16. #32
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    i found command tar its used to zip the folder and unzip the folder..i executed in terminal its working properly for both zip and unzip,,while in qt i used to unzip the folder (Remote.tar.gz) the output executed properly bt its not extract the Remote folder.
    Qt Code:
    1. QString program = "tar";
    2. arguments<<"-zxvf"<<"/home/digital_images/Desktop/Remote.tar.gz";
    3. gunzip.start(program, arguments);
    To copy to clipboard, switch view to plain text mode 
    i getting the output
    Qt Code:
    1. Remote/
    2. Remote/0/
    3. Remote/0/light.jpg
    To copy to clipboard, switch view to plain text mode 
    after the execution complete while in desktop my remote.tar.gz not extracted what am doing wrong here

  17. #33
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to unzip the file in qt using gzip

    What you are doing wrong is that you just want other people to solve your problems for you. You ignore the advice given to you, you do not read the documentation, you do not check (and tell us about) any error/return codes. I will only say this about your last question:
    * what is the exit code of the tar process?
    * what directory do you expect tar to extract the files to?
    These are just the points I would start with. Good luck, and please try seriously to solve your problem before posting again.

  18. #34
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to unzip the file in qt using gzip

    Quote Originally Posted by iswaryasenthilkumar View Post
    waitForFinished() error: Process operation timed out
    QProcess: Destroyed while process is still running.
    The error is shown above, QProcess::waitForFinished() reached the default timeout value (30,000 milliseconds or 30 seconds). Read the documentation to see if there's a way to prevent it from timing out.

  19. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (26th March 2015)

  20. #35
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    first i tried for unzip the file now am trying to unzip the folder.thats why i choosed tar linux command
    to compress
    Qt Code:
    1. tar -zcvf digitalimages.tar.gz<directory>
    To copy to clipboard, switch view to plain text mode 
    and to uncompress
    Qt Code:
    1. tar -zxvf digitalimages.tar.gz
    To copy to clipboard, switch view to plain text mode 
    while i using this command in terminal its executing properly while am using in qt umcompress command its not extracted,the zip folder contains images of folder inside
    Quote Originally Posted by yeye_olive View Post
    What you are doing wrong is that you just want other people to solve your problems for you. You ignore the advice given to you, you do not read the documentation, you do not check (and tell us about) any error/return codes. I will only say this about your last question:
    * what is the exit code of the tar process?
    * what directory do you expect tar to extract the files to?
    These are just the points I would start with. Good luck, and please try seriously to solve your problem before posting again.

  21. #36
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to unzip the file in qt using gzip

    Quote Originally Posted by iswaryasenthilkumar View Post
    while i using this command in terminal its executing properly while am using in qt umcompress command its not extracted,the zip folder contains images of folder inside
    Your posts stating it doesn't work are of no value if you don't show your code and output.

  22. #37
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    my code
    Qt Code:
    1. bool success;
    2. QProcess gunzip;
    3. QStringList arguments;
    4. gunzip.setProcessChannelMode(QProcess::MergedChannels);
    5. QString program = "tar";
    6. arguments<<"-zxvf"<<"/home/digital_images/Remote1.tar.gz";
    7. gunzip.start(program, arguments);
    8. success = gunzip.waitForStarted();
    9. if (!success)
    10. {
    11. qDebug("waitForStarted() error: %s", gunzip.errorString().toUtf8().constData());
    12. return;
    13. }
    14. success = gunzip.waitForFinished();
    15. if (!success)
    16. {
    17. qDebug("waitForFinished() error: %s", gunzip.errorString().toUtf8().constData());
    18. return;
    19. }
    20. QByteArray buffer = gunzip.readAll();
    21. QString output = buffer;
    22. qDebug("%s", output.toUtf8().constData());
    To copy to clipboard, switch view to plain text mode 
    output:
    Qt Code:
    1. Remote1/ //folder
    2. Remote1/0/ //0 folder
    3. Remote1/0/light.jpg //inside 0 foler one image i putted
    To copy to clipboard, switch view to plain text mode 
    What am doing wrong here please help me to get proper result
    Quote Originally Posted by jthomps View Post
    Your posts stating it doesn't work are of no value if you don't show your code and output.

  23. #38
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to unzip the file in qt using gzip

    Looks like it works to me. Why do you say it's not working?

  24. #39
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to unzip the file in qt using gzip

    bt i cant c my extracted folder,??

  25. #40
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to unzip the file in qt using gzip

    What is the current working directory when your app runs? I am sure it's creating the folders and extracting the file, but that's being done in the current working directory.

    If you want to control where the files are extracted to, look at "man tar" and see if the "-C" program argument might be of benefit to you. Your other option would be to change your working directory when your app is running.

  26. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (26th March 2015)

Similar Threads

  1. unzip zip file contains files and folders with quazip
    By nhocjerry in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2013, 09:19
  2. Need simple example with OSDaB-Zip unzip file
    By noborder in forum Newbie
    Replies: 2
    Last Post: 17th January 2013, 22:59
  3. unZip via 7z.
    By noborder in forum Newbie
    Replies: 9
    Last Post: 23rd December 2012, 20:26
  4. How to Zip/Unzip with QT for symbian???
    By baka3k in forum Newbie
    Replies: 2
    Last Post: 22nd June 2011, 09:24
  5. OpenOffice file to QTextEdit (Unzip Problem)
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2006, 11:32

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.