#include <QtCore>
// A hello world program to demonstrate the use of the global thread pool
// hellothreadpool/main.cpp
class Work : public QRunnable
{
public:
void run()
{
qDebug() << "Hello from thread " << QThread::currentThread();
}
};
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Work work;
work.setAutoDelete(false);
QThreadPool *threadPool = QThreadPool::globalInstance(); //使用公共线程池
threadPool->start(&work);
qDebug() << "hello from GUI thread " << QThread::currentThread();
threadPool->waitForDone();
return 0;
}
// A hello world program to demonstrate the use of the global thread pool
// hellothreadpool/main.cpp
class Work : public QRunnable
{
public:
void run()
{
qDebug() << "Hello from thread " << QThread::currentThread();
}
};
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
Work work;
work.setAutoDelete(false);
QThreadPool *threadPool = QThreadPool::globalInstance(); //使用公共线程池
threadPool->start(&work);
qDebug() << "hello from GUI thread " << QThread::currentThread();
threadPool->waitForDone();
return 0;
}