Results 1 to 10 of 10

Thread: unZip via 7z.

  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.

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

    Default Re: unZip via 7z.

    At final i have

    comicview.h
    Qt Code:
    1. #ifndef COMICVIEW_H
    2. #define COMICVIEW_H
    3.  
    4. #include "unzip.h"
    5.  
    6. #include <QMainWindow>
    7. #include <QProcess>
    8. #include <QFileDialog>
    9. #include <QMessageBox>
    10. #include <QString>
    11.  
    12. namespace Ui {
    13. class ComicView;
    14. }
    15.  
    16. class ComicView : public QMainWindow
    17. {
    18. Q_OBJECT
    19. public:
    20. explicit ComicView(QWidget *parent = 0);
    21. ~ComicView();
    22. private slots:
    23. void on_actionExit_triggered();
    24. void on_actionOpen_triggered();
    25. signals:
    26. void signal_unzip_file(QString filename);
    27. private:
    28. Ui::ComicView *ui;
    29. UnZip m_unzip;
    30. };
    31.  
    32. #endif // COMICVIEW_H
    To copy to clipboard, switch view to plain text mode 

    comicview.cpp
    Qt Code:
    1. #include "comicview.h"
    2. #include "ui_comicview.h"
    3.  
    4. ComicView::ComicView(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::ComicView)
    7. {
    8. ui->setupUi(this);
    9. connect( ui->actionExit, SIGNAL(triggered()), this, SLOT(close()) );
    10. connect( ui->actionOpen, SIGNAL(triggered()), this, SLOT(open()) );
    11.  
    12. connect(this, SIGNAL(signal_unzip_file(QString)), &m_unzip, SLOT(unzipfile(QString)));
    13. }
    14.  
    15. ComicView::~ComicView()
    16. {
    17. delete ui;
    18. }
    19.  
    20.  
    21. void ComicView::on_actionExit_triggered()
    22. {
    23. statusBar()->showMessage(tr("exit"), 2000);
    24. }
    25.  
    26.  
    27.  
    28. void ComicView::on_actionOpen_triggered()
    29. {
    30. QString fileName = QFileDialog::getOpenFileName(
    31. this, tr("Open File"),"", tr("Files (*.cbz)"));
    32. if (fileName != "") {
    33. QFile file(fileName);
    34. if (!file.open(QIODevice::ReadOnly)) {
    35. QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
    36. return;
    37. }
    38. }
    39. emit signal_unzip_file(fileName);
    40. }
    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. #include <QString>
    6.  
    7. class UnZip: public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. QProcess unZipproc;
    12. explicit UnZip(QObject *parent = 0);
    13. public slots:
    14. void unzipfile(QString filename);
    15.  
    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);
    12. }
    To copy to clipboard, switch view to plain text mode 

    and recieve error - ..\comicview\\unzip.h:8: error: undefined reference to `vtable for UnZip'
    ------------


    ookk new qmake solve the problem


    Added after 45 minutes:


    rewrite unzip as

    Qt Code:
    1. void UnZip::unzipfile(QString filename)
    2. {
    3. QString program = "/7-Zip/7z.exe";
    4. list << "x" << filename << "-oc:\comictemp" << "-r";
    5. unZipproc.startDetached(program, list);
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    at open .cbz in program run windows console. show unzip process, but at finish folder comictemp on C: doesn`t exist.

    When i write this comand at windows cmd, all work right and folder with files exist.

    What is wrong?

    -------------

    okk need second \ before c:
    list << "x" << filename << "-oc:\\comictemp" << "-r";
    Last edited by noborder; 22nd December 2012 at 17:53.

  8. #8
    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.

    you need to escape back slashes in c++:
    Qt Code:
    1. void UnZip::unzipfile(QString filename)
    2. {
    3. QString program = "/7-Zip/7z.exe";
    4. list << "x" << filename << "-oc:\\comictemp" << "-r"; /* note double \\ here */
    5. unZipproc.startDetached(program, list);
    6. }
    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.

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

    Default Re: unZip via 7z.

    how i can chek name of new folder in c:\\comictemp after unZip ?

    Errors

    Qt Code:
    1. void UnZip::unzipfile(QString filename)
    2. {
    3. QDir dir("/comictemp/");
    4. uint dirCountBefore = dir.count();
    5.  
    6. QString program = "/7-Zip/7z.exe";
    7. list << "x" << filename << "-oc:\\comictemp" << "-r";
    8. unZipproc.startDetached(program, list);
    9.  
    10.  
    11. if (!(dir.count - dirCountBefore)>0) { // <- Error 1
    12. // ........
    13. return;
    14. }
    15. QFileInfoList dirContent = dir.entryInfoList(QStringList()); // <- Error 2
    16. emit signal_unzip_done(QString dirContent);
    17. }
    To copy to clipboard, switch view to plain text mode 

    1:invalid use of member (did you forget the '&' ?)
    2:expected primary-expression before 'dirContent'
    Last edited by noborder; 23rd December 2012 at 18:31.

  10. #10
    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.

    dir.count()
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.