Qt线程池

创建一个类继承自QRunnable:

class Thread02 : public QRunnable

重写run方法:

void run() override;

在main函数里面加入线程池:

Thread02 *th = new Thread02();
    QThreadPool::globalInstance()->start(th);

#include
#include
#include "Thread01.h"
#include "Thread02.h"
#include

using namespace std;


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    cout << "main thread" << QThread::currentThreadId() << endl;

    /*Thread01 th;
    th.start();*/

    Thread02 *th = new Thread02();
    QThreadPool::globalInstance()->start(th);

    cout << "main thread end" << endl;
    return a.exec();
}

你可能感兴趣的:(java,开发语言)