put the filemonitor into a seperate thread and connected an update signal

This commit is contained in:
Crylia
2024-06-08 03:39:04 +02:00
parent 322659d210
commit b1cfa155f9
8 changed files with 97 additions and 48 deletions

View File

@@ -1,16 +1,26 @@
#include "FileController.hpp"
#include <chrono>
#include <memory>
#include <iostream>
FileController::FileController() {
m_fmWorker = std::make_unique<FileMonitor>(QString("/home/crylia/"),
std::chrono::milliseconds(1000));
FileController::FileController( ) {
m_fmWorker = std::make_shared<FileMonitor>(QString("/home/crylia/Dokumente"),
std::chrono::milliseconds(1000));
m_fmWorker->moveToThread(&m_fsThread);
m_fmWorker->start(QString("/home/crylia/"));
connect(this, &FileController::operate, m_fmWorker.get( ), &FileMonitor::start);
connect(m_fmWorker.get( ), &FileMonitor::update, this, &FileController::update);
m_fsThread.start( );
emit operate( );
}
FileController::~FileController() {
m_fsThread.quit();
m_fsThread.wait();
FileController::~FileController( ) {
m_fsThread.quit( );
m_fsThread.wait( );
}
void FileController::update(const QString path, const FileEvent event) {
std::cout << path.toStdString( ) << std::endl;
}

View File

@@ -8,11 +8,23 @@
class FileController : public QObject {
Q_OBJECT
public:
FileController();
~FileController();
FileController( );
~FileController( );
private:
QThread m_fsThread;
std::unique_ptr<FileMonitor> m_fmWorker;
std::shared_ptr<FileMonitor> m_fmWorker;
private slots:
void update(const QString path, const FileEvent);
signals:
// Start signal to start the function in the thread
void operate( );
// Stop signal to stop the function in the thread
void pause( );
// Signal to update the path inside the thread
void updatePath(const QString&);
};