Hi everyone.

I'm working on a little desktop gui app, which starts some other thread which would watch for changes in a certain file. I know I don't need a second thread for this, but would really like to, since I would do some time consuming processing on that file change event and would like to keep my main thread where gui app resides, still responsive to user comands.

Ok, so I have my second thread, but the problem is, that I can not connect signal-slot in it. The message I get at run time is "QObject::connect: No such slot QThread::HandleFileChange(const QString)". The relevant part of the code is bellow. Much thanks for help.

worker.h
Qt Code:
  1. #ifndef WORKER_H
  2. #define WORKER_H
  3. #include <QThread>
  4. #include <QFileSystemWatcher>
  5.  
  6. class Worker: public QThread
  7. {
  8. public:
  9. Worker(QString SrcFileParam,QString WorkerFolderParam);
  10.  
  11. void run();
  12.  
  13. private:
  14. QString SrcFilename,WorkerFolder;
  15. int Cntr;
  16. QFileSystemWatcher * watcher;
  17.  
  18. public slots:
  19. void HandleFileChange(const QString fileName);
  20.  
  21. };
  22.  
  23. #endif // WORKER_H
To copy to clipboard, switch view to plain text mode 

worker.cpp
Qt Code:
  1. #include "Worker.h"
  2. #include <iostream>
  3. #include <QMessageBox>
  4. #include <QFile>
  5. #include <QFileInfo>
  6.  
  7. Worker::Worker(QString SrcFileParam,QString WorkerFolderParam)
  8. {
  9. SrcFilename = SrcFileParam;
  10. WorkerFolder = WorkerFolderParam;
  11.  
  12. watcher = new QFileSystemWatcher(this);
  13. watcher->addPath(this->SrcFilename);
  14.  
  15. }
  16.  
  17. void Worker::run() {
  18. connect(watcher,SIGNAL(fileChanged(QString)),this,SLOT(HandleFileChange(const QString))); //problematical line
  19. for (int i=1;i<100;i++) {
  20. //std::cout << qPrintable(i);
  21. //std::cout << "printed from Worker class \nl";
  22. //QMessageBox::information(0,tr("Info"),QString::number(i));
  23. }
  24.  
  25. }
  26.  
  27. void Worker::HandleFileChange(const QString fileName) {
  28. // some code
  29. }
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. Worker wkr1(ui->lineEdit->text(),ui->lineEdit_2->text());
  2. wkr1.start();
  3. wkr1.wait();
To copy to clipboard, switch view to plain text mode