Q_OBJECT
public:
worker()//constructor
public slots:
void process(); // do your work here
signals:
void finished(); // emit when done
};
class Worker : public QObject {
Q_OBJECT
public:
worker()//constructor
public slots:
void process(); // do your work here
signals:
void finished(); // emit when done
};
To copy to clipboard, switch view to plain text mode
and connect it in a way similar to this:
Worker* worker = new Worker();
worker->moveToThread(thread);
connect(thread, SIGNAL(started()), worker, SLOT(process()));
connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
QThread* thread = new QThread;
Worker* worker = new Worker();
worker->moveToThread(thread);
connect(thread, SIGNAL(started()), worker, SLOT(process()));
connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
To copy to clipboard, switch view to plain text mode
That would be a good way of working with threads in Qt and its quit interesting and flexible and easy.
hope that helps Best Reagrds.
Bookmarks