This works, but am not sure the file change is processed by second thread now. Can you please review the code, thanks
worker.h
#ifndef WORKER_H
#define WORKER_H
#include <QThread>
#include <QFileSystemWatcher>
#include <QObject>
{
Q_OBJECT
public:
private:
int Cntr = 0;
public slots:
void HandleFileChange
(const QString fileName
);
};
#endif // WORKER_H
#ifndef WORKER_H
#define WORKER_H
#include <QThread>
#include <QFileSystemWatcher>
#include <QObject>
class Worker : public QObject
{
Q_OBJECT
public:
Worker(QString SrcFileParam,QString WorkerFolderParam);
private:
QString SrcFilename,WorkerFolder;
int Cntr = 0;
QFileSystemWatcher * watcher;
public slots:
void HandleFileChange(const QString fileName);
};
#endif // WORKER_H
To copy to clipboard, switch view to plain text mode
worker.cpp
#include "Worker.h"
#include <iostream>
#include <QMessageBox>
#include <QFile>
#include <QFileInfo>
{
SrcFilename = SrcFileParam;
WorkerFolder = WorkerFolderParam;
watcher->addPath(this->SrcFilename);
connect(watcher,
SIGNAL(fileChanged
(QString)),
this,
SLOT(HandleFileChange
(const QString)));
}
void Worker
::HandleFileChange(const QString fileName
) { qDebug("HandleFileChange triggered...");
}
#include "Worker.h"
#include <iostream>
#include <QMessageBox>
#include <QFile>
#include <QFileInfo>
Worker::Worker(QString SrcFileParam,QString WorkerFolderParam)
{
SrcFilename = SrcFileParam;
WorkerFolder = WorkerFolderParam;
watcher = new QFileSystemWatcher();
watcher->addPath(this->SrcFilename);
connect(watcher,SIGNAL(fileChanged(QString)),this,SLOT(HandleFileChange(const QString)));
}
void Worker::HandleFileChange(const QString fileName) {
qDebug("HandleFileChange triggered...");
}
To copy to clipboard, switch view to plain text mode
procthread.h
#ifndef PROCTHREAD_H
#define PROCTHREAD_H
#include <QThread>
{
private:
public:
void run();
};
#endif // PROCTHREAD_H
#ifndef PROCTHREAD_H
#define PROCTHREAD_H
#include <QThread>
class ProcThread : public QThread
{
private:
QString SrcFilename,WorkerFolder;
public:
explicit ProcThread(QString SrcFileParam,QString WorkerFolderParam);
void run();
};
#endif // PROCTHREAD_H
To copy to clipboard, switch view to plain text mode
procthread.cpp
#include "procthread.h"
#include "Worker.h"
ProcThread
::ProcThread(QString SrcFileParam,
QString WorkerFolderParam
){
SrcFilename = SrcFileParam;
WorkerFolder = WorkerFolderParam;
}
void ProcThread::run() {
Worker wrkr1(SrcFilename,WorkerFolder);
exec();
}
#include "procthread.h"
#include "Worker.h"
ProcThread::ProcThread(QString SrcFileParam,QString WorkerFolderParam)
{
SrcFilename = SrcFileParam;
WorkerFolder = WorkerFolderParam;
}
void ProcThread::run() {
Worker wrkr1(SrcFilename,WorkerFolder);
exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
procth1 = new ProcThread(ui->lineEdit->text(),ui->lineEdit_2->text());
procth1->start();
procth1 = new ProcThread(ui->lineEdit->text(),ui->lineEdit_2->text());
procth1->start();
To copy to clipboard, switch view to plain text mode
Bookmarks