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
  • What's the type of procQueueList? Commented Nov 30, 2009 at 14:06

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

...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. or 2) 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
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.
Starting QProcesses in new threads, which is unnecessary (if I may disagree). By the nature of the signal/slots system of QProcess, just start as needed (in a loop, line after line), then connect to the finished() signals, readLine(), etc. to get data back. Use kill() to terminate. There is no need to multithread or use blocking methods such as waitForFinished(). I have successfully maintained 3 or more processes at a time without threading.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.