然后创建一个QThread线程,把整个MyTaskClass类的实例move到线程中就可以了:
#include <QtWidgets/QApplication>
#include <QThread>
#include "MyTaskClass.hpp"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QThread* backgroundThread = new QThread;
backgroundThread->start();
MyTaskClass *task = new MyTaskClass();
task->moveToThread(backgroundThread);
MainWindow w;
w.show();
return a.exec();
}