PDA

View Full Version : unZip via 7z.



noborder
21st December 2012, 21:22
i`m totaly newbie. i`m write some code. need conect open action to unzip. hoow. and need to cmplete unZip process.



comicview.cpp


.............
.............
.............
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;
}
}
}



unzip.h


#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 unzipprocess();
void setfilename();
};

#endif // UNZIP_H



unzip.cpp


#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);
}

amleto
21st December 2012, 21:39
comicview.cpp


.............
.............
.............
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); // need to connect this signal to instance of UnZip's slot unzipfile
// or just call it directly:
// UnZip sevenZ;
// sevenZ.unzipfile(fileName);
}
}



unzip.h


#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



unzip.cpp


#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); // startDetached is fine for your needs
}

noborder
21st December 2012, 21:55
emit signal_unzip_file(fileName); // need to connect this signal to instance of UnZip's slot unzipfile

How connect?

i do

comicview.h

signals:
signal_unzip_file();

unZip.h

public slots:
void unzipprocess();

and what need to do with QObject::connect

amleto
22nd December 2012, 00:23
ComicView::ComicView()
{
// or somewhere sensible

m_unzip; // add 'UnZip m_unzip;' to ComicView header

connect(this, SIGNAL(signal_unzip_file(QString)), &m_unzip, SLOT(unzipfile(QString)));
}

I already showed you that you should change your signal and slots...

noborder
22nd December 2012, 11:19
I'm confused. Please see the attachment

amleto
22nd December 2012, 12:56
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!!

noborder
22nd December 2012, 18:39
At final i have

comicview.h

#ifndef COMICVIEW_H
#define COMICVIEW_H

#include "unzip.h"

#include <QMainWindow>
#include <QProcess>
#include <QFileDialog>
#include <QMessageBox>
#include <QString>

namespace Ui {
class ComicView;
}

class ComicView : public QMainWindow
{
Q_OBJECT
public:
explicit ComicView(QWidget *parent = 0);
~ComicView();
private slots:
void on_actionExit_triggered();
void on_actionOpen_triggered();
signals:
void signal_unzip_file(QString filename);
private:
Ui::ComicView *ui;
UnZip m_unzip;
};

#endif // COMICVIEW_H

comicview.cpp

#include "comicview.h"
#include "ui_comicview.h"

ComicView::ComicView(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ComicView)
{
ui->setupUi(this);
connect( ui->actionExit, SIGNAL(triggered()), this, SLOT(close()) );
connect( ui->actionOpen, SIGNAL(triggered()), this, SLOT(open()) );

connect(this, SIGNAL(signal_unzip_file(QString)), &m_unzip, SLOT(unzipfile(QString)));
}

ComicView::~ComicView()
{
delete ui;
}


void ComicView::on_actionExit_triggered()
{
statusBar()->showMessage(tr("exit"), 2000);
}



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);
}

unzip.h

#ifndef UNZIP_H
#define UNZIP_H
#include <QProcess>
#include <QObject>
#include <QString>

class UnZip: public QObject
{
Q_OBJECT
public:
QProcess unZipproc;
explicit UnZip(QObject *parent = 0);
public slots:
void unzipfile(QString filename);

};

#endif // UNZIP_H

unzip.cpp

#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);
}

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


void UnZip::unzipfile(QString filename)
{
QString program = "/7-Zip/7z.exe";
QStringList list;
list << "x" << filename << "-oc:\comictemp" << "-r";
unZipproc.startDetached(program, list);

}

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";

amleto
22nd December 2012, 18:49
you need to escape back slashes in c++:


void UnZip::unzipfile(QString filename)
{
QString program = "/7-Zip/7z.exe";
QStringList list;
list << "x" << filename << "-oc:\\comictemp" << "-r"; /* note double \\ here */
unZipproc.startDetached(program, list);
}

noborder
23rd December 2012, 14:56
how i can chek name of new folder in c:\\comictemp after unZip ?

Errors


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) { // <- Error 1
// ........
return;
}
QFileInfoList dirContent = dir.entryInfoList(QStringList()); // <- Error 2
emit signal_unzip_done(QString dirContent);
}

1:invalid use of member (did you forget the '&' ?)
2:expected primary-expression before 'dirContent'

amleto
23rd December 2012, 20:26
dir.count()