开发者

qt - qprocess start in a loop

开发者 https://www.devze.com 2022-12-12 17:26 出处:网络
I am calling a process in a loop. Need to ensure that one process ends before it starts again. how is it possible.

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-&开发者_如何转开发gt;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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号