Skip to content

Commit

Permalink
Merge pull request #4 from antony-jr/fix_bad_practice_on_qthread
Browse files Browse the repository at this point in the history
Fix bad practice on qthread
  • Loading branch information
antony-jr authored Jan 11, 2018
2 parents cb7f756 + a47dce1 commit 98bbf59
Show file tree
Hide file tree
Showing 28 changed files with 411 additions and 2,067 deletions.
480 changes: 358 additions & 122 deletions QArchive.hpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/AddingToYourQtProject.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ sidebar_label: Adding QArchive to Your Qt Project
| | |
|-----------|----------------------------------|
| Header: | #include "QArchive/QArchive.hpp" |
| qmake: | QT += core |
| qmake: | QT += core concurrent |
| | LIBS += -larchive |
| | HEADERS += QArchive/QArchive.hpp |
|Inherits: | [QThread](http://doc.qt.io/qt-5/qthread.html)|
| Inherits: | QObject |

**QArchive** is just a header and all you have to do after installation is to add
it in your **.pro** file ( **Qt Project file** ).
Expand All @@ -20,7 +20,7 @@ it in your **.pro** file ( **Qt Project file** ).
Append these **lines** to your **Qt Project file**.

```
QT += core
QT += core concurrent
LIBS += -larchive
HEADERS += QArchive/QArchive.hpp
```
Expand Down
17 changes: 10 additions & 7 deletions docs/QArchiveCompressor.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ sidebar_label: QArchive::Compressor

### Slots

All slots used by you are **inherited** from **[QThread](http://doc.qt.io/qt-5/qthread.html)**

| | |
|---------------|-------------|
| **void** | start(void) |
| **void** | quit(void) |
| **void** | wait(void) |
| **void** | stop(void) |

### Signals

| | |
|---------------------|---------------------------------------------------------------------------------|
| **void** | stopped(void) |
| **void** | finished(void) |
| **void** | compressing(const QString& file) |
| **void** | compressed(const QString& file) |
Expand Down Expand Up @@ -74,12 +72,17 @@ Sets the format of the archive which is going to be created. refer the **[suppor
#### void start(void)
This member function is a **[SLOT]**

Starts the compression of all files in the archive. Inherited from **[QThread](http://doc.qt.io/qt-5/qthread.html)**.
Starts the compression of all files in the archive.

#### void quit(void)
#### void stop(void)
This member function is a **[SLOT]**

Quits the compressor thread. Inherited from **[QThread](http://doc.qt.io/qt-5/qthread.html)**
Stops the compressor. **void stopped(void)** signal will be emitted if this slot is successfull.

#### void stopped(void)
This member function is a **[SIGNAL]**

Emitted when **void stop(void)** is successfull.

#### void finished(void)
This member function is a **[SIGNAL]**
Expand Down
18 changes: 11 additions & 7 deletions docs/QArchiveExtractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ This class runs on a seperate thread to avoid blocking by **libarchive**.

### Slots

All slots used by you are **inherited** from **[QThread](http://doc.qt.io/qt-5/qthread.html)**

| | |
|---------------|-------------|
| **void** | start(void) |
| **void** | quit(void) |
| **void** | wait(void) |
| **void** | stop(void) |

### Signals

| | |
|---------------------|---------------------------------------------------------------------------------|
| **void** | stopped(void) |
| **void** | finished(void) |
| **void** | extracting(const QString& archive) |
| **void** | extracted(const QString& archive) |
Expand Down Expand Up @@ -84,12 +82,18 @@ Sets the destination where the archive(s) will be extracted. Default is **the pr
#### void start(void)
This member function is a **[SLOT]**

Starts the extraction of all archives in the queue. Inherited from **[QThread](http://doc.qt.io/qt-5/qthread.html)**.
Starts the extraction of all archives in the queue.

#### void quit(void)
#### void stop(void)
This member function is a **[SLOT]**

Quits the extraction thread. Inherited from **[QThread](http://doc.qt.io/qt-5/qthread.html)**
Stops the extraction of all archives in the queue. This slot is **asyc** and thus you need to wait for the
**void stopped(void)** signal , Which confirms that the stop call was successfull.

#### void stopped(void)
This member function is a **[SIGNAL]**

Emitted when **void stop(void)** is successfull , i.e When the extraction is stopped successfully.

#### void finished(void)
This member function is a **[SIGNAL]**
Expand Down
12 changes: 5 additions & 7 deletions docs/QArchiveReader.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ sidebar_label: QArchive::Reader

### Slots

All slots used by you are **inherited** from **[QThread](http://doc.qt.io/qt-5/qthread.html)**

| | |
|---------------|-------------|
| **void** | start(void) |
| **void** | quit(void) |
| **void** | wait(void) |
| **void** | stop(void) |

### Signals

| | |
|---------------------|---------------------------------------------------------------------------------|
| **void** | stopped(void) |
| **void** | archiveFiles(const QString& archive, const QStringList& files) |
| **void** | error(short **[errorCode](QArchiveErrorCodes.md)** , const QString& what) |

Expand All @@ -52,12 +50,12 @@ Clears all cached **filenames** and **archive paths**
#### void start(void)
This member function is a **[SLOT]**

Reads all files in the archive. Inherited from **[QThread](http://doc.qt.io/qt-5/qthread.html)**.
Start reading all files in the archive.

#### void quit(void)
#### void stop(void)
This member function is a **[SLOT]**

Quits the Reader thread. Inherited from **[QThread](http://doc.qt.io/qt-5/qthread.html)**
Stops the Reader. **void stopped(void)** signal is emitted when this is successfull.

#### void archiveFiles(const QString& archive, const QStringList& files)
This member function is a **[SIGNAL]**
Expand Down
5 changes: 2 additions & 3 deletions docs/UsingCompressor.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ int main(int argc, char** argv)
});
QObject::connect(&e, &QArchive::Compressor::error, [&](short code, QString file) {
qDebug() << "error code:: " << code << " :: " << file;
e.terminate();
app.quit();
});
/*
Expand All @@ -59,7 +58,7 @@ int main(int argc, char** argv)
TEMPLATE = app
TARGET = create_archive
QT += core
QT += core concurrent
LIBS += -larchive
SOURCES += main.cpp
HEADERS += QArchive/QArchive.hpp
Expand All @@ -70,7 +69,7 @@ HEADERS += QArchive/QArchive.hpp
```
$ mkdir build
$ cd build
$ qmake ../create_archive.pro
$ qmake ..
$ make -j4
$ ./create_archive
$ # Make sure you have files for the new archive!
Expand Down
6 changes: 2 additions & 4 deletions docs/UsingExtractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ int main(int argc, char** argv)
// emitted when all extraction is finished
QObject::connect(&e, &QArchive::Extractor::finished, [&]() {
qDebug() << "Finished all extraction!";
e.quit();
app.quit();
});
Expand All @@ -48,7 +47,6 @@ int main(int argc, char** argv)
// emitted when something goes wrong
QObject::connect(&e, &QArchive::Extractor::error, [&](short code, QString file) {
e.terminate();
switch(code) {
case QArchive::ARCHIVE_READ_ERROR:
qDebug() << "unable to find archive :: " << file;
Expand Down Expand Up @@ -86,7 +84,7 @@ int main(int argc, char** argv)
TEMPLATE = app
TARGET = extraction
QT += core
QT += core concurrent
LIBS += -larchive
SOURCES += main.cpp
HEADERS += QArchive/QArchive.hpp
Expand All @@ -97,7 +95,7 @@ HEADERS += QArchive/QArchive.hpp
```
$ mkdir build
$ cd build
$ qmake ../extraction.pro
$ qmake ..
$ make -j4
$ ./extraction
$ # Make sure you have test.7z file!
Expand Down
5 changes: 2 additions & 3 deletions docs/UsingReader.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ int main(int argc, char** argv)
QObject::connect(&e, &QArchive::Reader::archiveFiles, [&](QString archive, QStringList files) {
qDebug() << archive << " :: ";
qDebug() << files;
e.quit();
app.quit();
});
Expand Down Expand Up @@ -72,7 +71,7 @@ int main(int argc, char** argv)
TEMPLATE = app
TARGET = read_archive
QT += core
QT += core concurrent
LIBS += -larchive
SOURCES += main.cpp
HEADERS += QArchive/QArchive.hpp
Expand All @@ -83,7 +82,7 @@ HEADERS += QArchive/QArchive.hpp
```
$ mkdir build
$ cd build
$ qmake ../read_archive.pro
$ qmake ..
$ make -j4
$ ./read_archive
$ # Make sure you have archive file!
Expand Down
2 changes: 1 addition & 1 deletion examples/create_archive/create_archive.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TARGET = create_archive
INCLUDEPATH += . ../../
DEFINES += QT_DEPRECATED_WARNINGS

QT += core
QT += core concurrent
LIBS += -larchive
SOURCES += main.cpp
HEADERS += ../../QArchive.hpp
1 change: 0 additions & 1 deletion examples/create_archive/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ int main(int argc, char** argv)
});
QObject::connect(&e, &QArchive::Compressor::error, [&](short code, QString file) {
qDebug() << "error code:: " << code << " :: " << file;
e.terminate();
app.quit();
});
/*
Expand Down
4 changes: 4 additions & 0 deletions examples/examples.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS = create_archive extract_interrupt extract_to extraction read_archive
2 changes: 1 addition & 1 deletion examples/extract_interrupt/extract_interrupt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TARGET = extract_interrupt
INCLUDEPATH += . ../../
DEFINES += QT_DEPRECATED_WARNINGS

QT += core
QT += core concurrent
LIBS += -larchive
SOURCES += main.cpp
HEADERS += ../../QArchive.hpp
15 changes: 9 additions & 6 deletions examples/extract_interrupt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ int main(int argc, char** argv)
// emitted when all extraction is finished
QObject::connect(&e, &QArchive::Extractor::finished, [&]() {
qDebug() << "Finished all extraction!";
e.quit();
app.quit();
app.quit();
});

QObject::connect(&e, &QArchive::Extractor::extracting, [&](QString file) {
Expand All @@ -32,9 +31,14 @@ int main(int argc, char** argv)
qDebug() << "Extracted:: " << file;
});

QObject::connect(&e, &QArchive::Extractor::stopped,
[&](){
qDebug() << "Stopped Successfully!";
app.quit();
});

// emitted when something goes wrong
QObject::connect(&e, &QArchive::Extractor::error, [&](short code, QString file) {
e.terminate();
switch(code) {
case QArchive::ARCHIVE_READ_ERROR:
qDebug() << "unable to find archive :: " << file;
Expand All @@ -50,7 +54,6 @@ int main(int argc, char** argv)
break;
default:
qDebug() << "unknown error. :: " << file;
e.wait();
app.quit();
break;
}
Expand All @@ -63,8 +66,8 @@ int main(int argc, char** argv)

QTimer::singleShot(1000 , &app ,
[&](){
qDebug() << "Interruption Request!";
e.requestInterruption();
qDebug() << "Stopping extraction";
e.stop();
});
qDebug() << "Its Non-Blocking!";

Expand Down
2 changes: 1 addition & 1 deletion examples/extract_to/extract_to.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ INCLUDEPATH += . ../../
DEFINES += QT_DEPRECATED_WARNINGS

LIBS += -larchive
QT += core
QT += core concurrent

SOURCES += main.cpp
HEADERS += ../../QArchive.hpp
21 changes: 0 additions & 21 deletions examples/extraction/build/.qmake.stash

This file was deleted.

Loading

0 comments on commit 98bbf59

Please sign in to comment.