.............void ComicView::on_actionOpen_triggered(){ QString fileName = QFileDialog::getOpenFileName( this, tr("Open File"),"", tr("Files (*.cbz)")); if (fileName.isEmpty()) return;}
#ifndef UNZIP_H#define UNZIP_H#include <QProcess>#include <QObject>class UnZip: public QObject{ Q_OBJECTpublic: QProcess unZipproc; explicit UnZip(QObject *parent = 0);public slots: void unzipprocess();};#endif // UNZIP_H
#include "unzip.h"#include <QString>#include <QStringList>UnZip::UnZip(QObject *parent) : QObject(parent){}void UnZip::unzipprocess(){QStringList list;list << "e" << filename;unZipproc.start("7z", list);}
...if (fileName.isEmpty()) return;UnZip unzip;unzip.setFileName(fileName);unzip.unzipprocess()
............. ............. ............. void ComicView::on_actionOpen_triggered() { QString fileName = QFileDialog::getOpenFileName( this, tr("Open File"),"", tr("Files (*.cbz)")); if (fileName != "") { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("Error"), tr("Could not open file")); return; } emit signal_unzip_file(fileName); } }
#ifndef UNZIP_H #define UNZIP_H #include <QProcess> #include <QObject> class UnZip: public QObject { Q_OBJECT public: QProcess unZipproc; explicit UnZip(QObject *parent = 0); public slots: void unzipfile(QString filename); }; #endif // UNZIP_H
#include "unzip.h" #include <QString> #include <QStringList> UnZip::UnZip(QObject *parent) : QObject(parent) {} void UnZip::unzipfile(QString filename) { QStringList list; list << "e" << filename; unZipproc.startDetached("7z", list); }
signals: void signal_unzip_file(QString filename);
ComicView::ComicView(QWidget *parent) :...........{ ......... connect(this, SIGNAL(signal_unzip_file(QString)), &m_unzip, SLOT(unzipfile(QString)));}
public slots: void unzipfile(QString filename);
#include "unzip.h"..................privateUnZip m_zip;
void UnZip::unzipfile(QString filename){ QString program = "/7-Zip/7z.exe"; QStringList list; list << "x" << filename << "-oc:\comictemp" << "-r"; unZipproc.startDetached(program, list);}
void UnZip::unzipfile(QString filename){ QDir dir("/comictemp/"); uint dirCountBefore = dir.count(); QString program = "/7-Zip/7z.exe"; QStringList list; list << "x" << filename << "-oc:\\comictemp" << "-r"; unZipproc.startDetached(program, list); if (!(dir.count() - dirCountBefore)>0) { //ошибка // ................ return; }QFileInfoList dirContent = dir.entryInfoList(QStringList()); // <- ошибка emit signal_unzip_done(QString dirContent);}