-
Notifications
You must be signed in to change notification settings - Fork 27
Class QArchive::Reader
Antony jr edited this page Dec 17, 2017
·
7 revisions
The Reader makes it easy for you to list all files in an archive
, This can be very usefull sometimes. ❤️
Reader(QObject *parent = NULL) | |
---|---|
Reader(const QString&) | Sets a single archive and Constructs the reader. |
void setArchive(const QString&) | Sets a single archive. |
---|---|
const QStringList& listFiles() | Get the files stored in this class. |
void clear() | Clears everything stored in this class. |
void start(void) | Starts or resumes the reader. (Inherited from QThread) |
---|---|
Stoping and Terminating | Refer QtDocs for information on stoping QThread. |
void archiveFiles(const QString& , const QStringList&) | Emitted when we got all the files from the archive. |
---|---|
void error(short , const QString&) | Emitted when something goes wrong. |
Step #1 : Construct.
QArchive::Reader ArchiveReader("test.7z");
Step #2 : Connect Callbacks.
QObject::connect(&ArchiveReader, &QArchive::Reader::archiveFiles,
[&](QString archive, QStringList files) {
qDebug() << archive << " :: ";
qDebug() << files;
ArchiveReader.quit();
app.quit();
});
Step #3 : Start the Reader.
ArchiveReader.start() // never use .run() method directly.
#include <QCoreApplication>
#include <QDebug>
#include "QArchive.hpp"
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
/*
* 1.Construct
*/
QArchive::Reader e("test.7z");
/*
* 2.Connect Callbacks
*/
QObject::connect(&e, &QArchive::Reader::archiveFiles,
[&](QString archive, QStringList files) {
qDebug() << archive << " :: ";
qDebug() << files;
e.quit();
app.quit();
});
// emitted when something goes wrong
QObject::connect(&e, &QArchive::Reader::error,
[&](short code, QString file) {
switch(code) {
case QArchive::ARCHIVE_READ_ERROR:
qDebug() << "unable to find archive :: " << file;
app.quit();
break;
case QArchive::ARCHIVE_QUALITY_ERROR:
qDebug() << "bad archive! :: " << file;
app.quit();
break;
case QArchive::ARCHIVE_UNCAUGHT_ERROR:
qDebug() << "fatal error. :: " << file;
app.quit();
break;
default:
qDebug() << "unknown error. :: " << file;
app.quit();
break;
}
});
/*
* 3.Start extraction!
*/
e.start();
return app.exec();
}
BSD 3-Clause License
Copyright (C) 2017 , antony-jr
All Rights Reserved.