要疯了,怎样用多线程向MYSQL数据库中写入数据
1个回答
2016-02-05 · 知道合伙人互联网行家
关注
展开全部
#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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询