PDA

View Full Version : Working with QThread



Fastman
27th February 2009, 14:10
Prompt how to implement the following features:

My application is a lot Thread server and receives the job to copy files from one directory to another. After receives a job is entered into the database and get in the queue.With the help of a timer, I queried the database every 10 seconds, and derive from the base of your new job. Each new task of copying a file is executed in a separate thread.Now you need to be able to suspend the execution in advance of copying the file / interrupt the flow.
Prompt how to make sure that I at any time to stop the flow.

application of this:




void Server::TimerShot()
{
CWorkThread *WThread = new CWorkThread(this);
connect(WThread, SIGNAL(finished()), WThread, SLOT(deleteLater()));
WThread->start(QThread::HighPriority);
}






void CWorkThread::run()
{
CWorkFiles files;

sInfo = db.GetNewTask();
db.CloseDB();

//File Operation blocked. While the file is not copied more than walk.
if(files.CopyFileExPrg(QDir::toNativeSeparators(sI nfo.cFileName),
QDir::toNativeSeparators(sGInfo.cDstPath), true, false, sInfo.nSysId))
{
//OK
db.ChangeState(3, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
db.CloseDB();
break;
}
else
{
//ERROR
db.ChangeState(33, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
db.CloseDB();
break;
}
}

wysota
27th February 2009, 22:35
I suggest you read about QThreadPool and QRunnable and QFuture.