tags:

views:

240

answers:

2

I am calling a process in a loop. Need to ensure that one process ends before it starts again. how is it possible.

    void MainWindow::setNewProjectInQueueList()
{
//  this is already gotten in queueList now loop thru the list and add project
    QStringList arguments;
    projNm = ui->lineEditCreateProject->text();
    qDebug() << " projNm " << projNm;
    for (int j= 0; j < queueList.length(); j++)
    {   if (! QString(queueList[j]).isEmpty())
        {
//          call process
//          QString queueName = queueList[j];
            arguments << "-sq" << queueList[j];
            qDebug() << " arguments sq " << queueList[j];
            procQueueList.start("qconf",arguments);

        }
    }

//  and append for each queue with new project name
//  and store into the system
}

Brgds,

kNish

+1  A: 

Call QProcess::waitForFinished() to wait until the process terminates.

Aaron Digulla
A: 

Using the waitForFinished approach from within a loop in the main thread will freeze the application. Instead, putting the loop in a separate thread, or making a queue of processes to start and then launch upon the finished signal from the previous one is good alternatives.

e8johan
...correct me if i am wrong...what i gather from what yo have said so far is..1) create a seperate thread ( new thread ). here are you saying i should make a seperate thread for each new process in the loop. then what.or2) making a queue ... - From this what i understand is using thread make a queue of processes. launch one after the previous has comepleted. Brgds,knish
knishua
Actually, two different solutions. Either the one you have, but with waitForFinished, with your loop running in a separate thread. Or, create a queue from which you start one process at a time. When each process is done, they emit a signal (finished). On that signal, try launching the next process.
e8johan