Results 1 to 20 of 31

Thread: unzip and untar into new directory

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default unzip and untar into new directory

    I have a file that is file.tar.gz and I would like to implement an open function from GUI menu that allows the user to select the tar.gz file and the application unzip, untar, and place those files in a specified directory. I don't think there is a Qt function that can do all of the above (but maybe some) but I was curious on any suggestions on how to implement this functionality.

    Thanks for any help!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unzip and untar into new directory

    use QProcess to start an unzip utility e.g. 7z or equivalent.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: unzip and untar into new directory

    Is there anyway to do it without using QProcess? I am trying to avoid needing to install any third party software with my application.

  4. #4
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: unzip and untar into new directory

    Ok so I have decided to use peazip for the QProcess but I do not understand how to use QProcess very well. I downloaded the peazip portable and placed the executable in the same directory as my application. I tried to do the following:

    Qt Code:
    1. MainWindow::open()
    2. {
    3. QProcess *unarchive = new QProcess(this);
    4. QStringList arguments;
    5. arguments << "-ext2here" << "file.tar.gz";
    6. unarchive->start("peazip", arguments);
    7.  
    8. // other things happen
    9. }
    To copy to clipboard, switch view to plain text mode 

    Unfortunately nothing seems to be happening so I am curious what I am missing. Thanks for any help!

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: unzip and untar into new directory

    What sort of 'nothing' is happening? Is the QProcess object emitting an error() signal? Where is the peazip executable in relation to the current working directory of your process?

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unzip and untar into new directory

    how are you testing? by debugging through an IDE or just running your program 'manually'? If the former, you probably just have a problem where your app is not run from the same location as the unzip utility
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: unzip and untar into new directory

    Duh! I was running it in debug mode and didn't put the peazip executable in the correct directory... It seems to be working fine now!!

    I do have another question that might be answered here, can you do an OS check with Qt? I don't see a Linux version of the peazip portable so I am thinking I will need a #if statement to check for Windows OS and use peazip but if it is Linux use standard unix unarchiving/archiving commands. How would you call the unix terminal to unzip and untar a file?

    Thanks again for any help!

  8. #8
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: unzip and untar into new directory

    So I am able to have the QProcess execute the unzip and untar but when I try and run something after the untar nothing appears to be happening.

    Qt Code:
    1. QMainWindow::open()
    2. {
    3. if(okToContinue())
    4. {
    5. QString fileName = QFileDialog::getOpenFileName(this, tr("Open file.tar.gz file"), ".", tr("gzip tarball"
    6. "(*.tar.gz)"));
    7.  
    8. if(!fileName.isEmpty())
    9. {
    10. QProcess *unarchive = new QProcess(this);
    11.  
    12. QStringList arguments;
    13. arguments << "-ext2here" << fileName;
    14. unarchive->start("peazip", arguments);
    15.  
    16. if(unarchive->waitForFinished())
    17. {
    18. fileName.remove(".gz");
    19. arguments.clear();
    20. arguments << "-ext2here" << fileName;
    21. int exitCode = unarchive->execute("peazip", arguments);
    22.  
    23. if(unarchive->waitForFinish())
    24. {
    25. fileName.remove("file.tar");
    26. // this is the path that is extracted from tar and the .csv is what I am after
    27. fileName.append(("tmp/file/A.csv"));
    28.  
    29. loadFile(fileName);
    30. }
    31. }
    32. }
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    It never seems to make it inside the second waitForFinish if statement. What am I doing wrong?

    Thanks for help!

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unzip and untar into new directory

    why are you mixing execute/start? Why are you allocating on the heap when you only want a local instance?

    I believe the problem is that you are using execute, which is a static method, therefore the finished state required for 'waitForFinished' is not modified.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. How to Zip/Unzip with QT for symbian???
    By baka3k in forum Newbie
    Replies: 2
    Last Post: 22nd June 2011, 08:24
  2. No such file or directory
    By Bertbeeg in forum Newbie
    Replies: 4
    Last Post: 24th October 2010, 23:04
  3. get .pro directory
    By Alnitak in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2010, 18:43
  4. Specify the DLL directory
    By Nyphel in forum Newbie
    Replies: 6
    Last Post: 27th April 2007, 14:29
  5. OpenOffice file to QTextEdit (Unzip Problem)
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2006, 10: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
  •  
Qt is a trademark of The Qt Company.