-
Notifications
You must be signed in to change notification settings - Fork 27
Class QArchive::Compressor
Antony jr edited this page Dec 16, 2017
·
8 revisions
The Compressor Takes care of compression of archives with the help of libarchive.
This class runs on a seperate thread to avoid blocking by libarchive.
Compressor(QObject *parent = NULL) | |
---|---|
Compressor(const QString&) | Set the archive path only. |
Compressor(const QString& , const QString&) | Set the archive path and add a single file or folder. |
Compressor(const QString& , const QStringList&) | Set the archive path and add files and folder from the list. |
void addFiles(const QString&) | Add a file or folder to the list. |
---|---|
void addFiles(const QStringList&) | Add a set of files and folder to the list. |
void removeFiles(const QString&) | Remove's a files and folder from the list matching the QString. |
void removeFiles(const QStringList&) | emove's a files and folder from the list matching the QStringList. |
void setArchive(const QString&) | Sets the path for the new archive. |
void setArchiveFormat(short) | Sets the format of the archive. |
void start(void) | Starts or resumes the compression. (Inherited from QThread) |
---|---|
Stoping and Terminating | Refer QtDocs for information on stoping QThread. |
void finished() | Emitted when all extraction job is done. |
---|---|
void compressing(const QString&) | Emitted with the filename beign compressing. |
void compressed(const QString&) | Emitted with the filename that has been compressed. |
void error(short , const QString&) | Emitted when something goes wrong! This does provide the filename. |
Step #1 : Construct
QArchive::Compressor c("test.7z" , "TestDir");
Step #2 : Connect Callbacks.
QObject::connect(&c , &QArchive::Compressor::finished , [&]()
{
qDebug() << "All Jobs are done!";
QCoreApplication::quit();
});
Step #3 : start the QThread.
c.start()
#include <QCoreApplication>
#include <QDebug>
#include "QArchive.hpp"
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
/*
* 1.Construct
*/
QArchive::Compressor e("test.7z", "TestDir");
// Archive |--> Can also
// can be simply add
// detected directories.
// with extension.
/*
* 2.Connect Callbacks
*/
// emitted when all extraction is finished
QObject::connect(&e, &QArchive::Compressor::finished, [&]() {
qDebug() << "Finished all jobs";
app.quit();
});
QObject::connect(&e, &QArchive::Compressor::error, [&](short code, QString file) {
qDebug() << "error code:: " << code << " :: " << file;
e.terminate();
app.quit();
});
/*
* 3.Start extraction!
*/
e.start();
qDebug() << "Its Non-Blocking!";
return app.exec();
}
BSD 3-Clause License
Copyright (C) 2017 , antony-jr
All Rights Reserved.