Results 1 to 10 of 10

Thread: unZip via 7z.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default unZip via 7z.

    i`m totaly newbie. i`m write some code. need conect open action to unzip. hoow. and need to cmplete unZip process.



    comicview.cpp
    Qt Code:
    1. .............
    2. .............
    3. .............
    4. void ComicView::on_actionOpen_triggered()
    5. {
    6. QString fileName = QFileDialog::getOpenFileName(
    7. this, tr("Open File"),"", tr("Files (*.cbz)"));
    8. if (fileName != "") {
    9. QFile file(fileName);
    10. if (!file.open(QIODevice::ReadOnly)) {
    11. QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
    12. return;
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 


    unzip.h
    Qt Code:
    1. #ifndef UNZIP_H
    2. #define UNZIP_H
    3. #include <QProcess>
    4. #include <QObject>
    5.  
    6. class UnZip: public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. QProcess unZipproc;
    11. explicit UnZip(QObject *parent = 0);
    12.  
    13.  
    14. public slots:
    15. void unzipprocess();
    16. void setfilename();
    17. };
    18.  
    19. #endif // UNZIP_H
    To copy to clipboard, switch view to plain text mode 


    unzip.cpp
    Qt Code:
    1. #include "unzip.h"
    2. #include <QString>
    3. #include <QStringList>
    4.  
    5. UnZip::UnZip(QObject *parent) : QObject(parent)
    6. {}
    7.  
    8. void UnZip::unzipprocess()
    9. {
    10. list << "e" << filename;
    11. unZipproc.start("7z", list);
    12. }
    To copy to clipboard, switch view to plain text mode 

  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 via 7z.

    comicview.cpp
    Qt Code:
    1. .............
    2. .............
    3. .............
    4. void ComicView::on_actionOpen_triggered()
    5. {
    6. QString fileName = QFileDialog::getOpenFileName(
    7. this, tr("Open File"),"", tr("Files (*.cbz)"));
    8. if (fileName != "") {
    9. QFile file(fileName);
    10. if (!file.open(QIODevice::ReadOnly)) {
    11. QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
    12. return;
    13. }
    14.  
    15. emit signal_unzip_file(fileName); // need to connect this signal to instance of UnZip's slot unzipfile
    16. // or just call it directly:
    17. // UnZip sevenZ;
    18. // sevenZ.unzipfile(fileName);
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 


    unzip.h
    Qt Code:
    1. #ifndef UNZIP_H
    2. #define UNZIP_H
    3. #include <QProcess>
    4. #include <QObject>
    5.  
    6. class UnZip: public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. QProcess unZipproc;
    11. explicit UnZip(QObject *parent = 0);
    12.  
    13.  
    14. public slots:
    15. void unzipfile(QString filename);
    16. };
    17.  
    18. #endif // UNZIP_H
    To copy to clipboard, switch view to plain text mode 


    unzip.cpp
    Qt Code:
    1. #include "unzip.h"
    2. #include <QString>
    3. #include <QStringList>
    4.  
    5. UnZip::UnZip(QObject *parent) : QObject(parent)
    6. {}
    7.  
    8. void UnZip::unzipfile(QString filename)
    9. {
    10. list << "e" << filename;
    11. unZipproc.startDetached("7z", list); // startDetached is fine for your needs
    12. }
    To copy to clipboard, switch view to plain text mode 
    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 2012
    Posts
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: unZip via 7z.


    Qt Code:
    1. emit signal_unzip_file(fileName); // need to connect this signal to instance of UnZip's slot unzipfile
    To copy to clipboard, switch view to plain text mode 

    How connect?

    i do

    comicview.h
    Qt Code:
    1. signals:
    2. signal_unzip_file();
    To copy to clipboard, switch view to plain text mode 

    unZip.h
    Qt Code:
    1. public slots:
    2. void unzipprocess();
    To copy to clipboard, switch view to plain text mode 

    and what need to do with QObject::connect
    Last edited by noborder; 21st December 2012 at 21:55.

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

    Default Re: unZip via 7z.

    Qt Code:
    1. ComicView::ComicView()
    2. {
    3. // or somewhere sensible
    4.  
    5. m_unzip; // add 'UnZip m_unzip;' to ComicView header
    6.  
    7. connect(this, SIGNAL(signal_unzip_file(QString)), &m_unzip, SLOT(unzipfile(QString)));
    8. }
    To copy to clipboard, switch view to plain text mode 
    I already showed you that you should change your signal and slots...
    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.

  5. #5
    Join Date
    Dec 2012
    Posts
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: unZip via 7z.

    I'm confused. Please see the attachment
    Attached Files Attached Files

  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 via 7z.

    There are demos in your qt installation. There are simple examples and tutorials online. There is very good documentation available. NO I will not look at your zip file if you're expecting me to write all the code for you!!
    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. unzip and untar into new directory
    By jshafferman in forum Qt Programming
    Replies: 30
    Last Post: 26th July 2012, 19:49
  2. How to Zip/Unzip with QT for symbian???
    By baka3k in forum Newbie
    Replies: 2
    Last Post: 22nd June 2011, 08:24
  3. OpenOffice file to QTextEdit (Unzip Problem)
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2006, 10:32

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
  •  
Qt is a trademark of The Qt Company.