如题所述
#include <QCoreApplication>
#include "thread.h"
#include <QVector>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QVector<Thread*> vector;
Thread *thread;
//å建å¤ä¸ªçº¿ç¨ï¼å¹¶start
for(int i=0;i<10;i++){
thread=new Thread;
vector.append(thread);
thread->set(i);
thread->start();
}
//çå¾ ææ线ç¨æ§è¡å®ï¼ç¶åå é¤çº¿ç¨
foreach(thread,vector){
thread->wait();
}
foreach(thread,vector){
delete thread;
}
return a.exec();
}
#include "thread.h"
#include <QVector>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QVector<Thread*> vector;
Thread *thread;
//å建å¤ä¸ªçº¿ç¨ï¼å¹¶start
for(int i=0;i<10;i++){
thread=new Thread;
vector.append(thread);
thread->set(i);
thread->start();
}
//çå¾ ææ线ç¨æ§è¡å®ï¼ç¶åå é¤çº¿ç¨
foreach(thread,vector){
thread->wait();
}
foreach(thread,vector){
delete thread;
}
return a.exec();
}
温馨提示:答案为网友推荐,仅供参考