workthreadctl.cpp 735 B

1234567891011121314151617181920212223242526272829
  1. #include "workthreadctl.h"
  2. #include "workerthread.h"
  3. WorkThreadCtl::WorkThreadCtl(QObject *parent): QObject(parent)
  4. {
  5. WorkerThread *worker = new WorkerThread;
  6. worker->moveToThread(&workerThread);
  7. connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
  8. connect(this, &WorkThreadCtl::operate, worker, &WorkerThread::doWork);
  9. //connect(worker, &WorkerThread::resultReady, this, &WorkThreadCtl::handleResults);
  10. workerThread.start();
  11. }
  12. WorkThreadCtl::~WorkThreadCtl()
  13. {
  14. workerThread.quit();
  15. workerThread.wait();
  16. }
  17. //提交信号,执行槽函数在多线程中
  18. void WorkThreadCtl::commitTask(std::function<int(void*)> fun, void * parameter)
  19. {
  20. operate(fun, parameter);
  21. }