I have a slot that is called passing some arguments used in a QProcess. I execute a external program with some of this arguments. The problem is that I want to have a queue for these processes, waiting until the previous process is finished to launch the next.
What do you think is the best/easiest way?
Here my method/slot:
void FirstCase::CallApp(QString text, QString pathAndFileName)
{
QString command = QString("App1.exe %1开发者_JAVA百科 -Z %2").arg(pathAndFileName).arg(message);
QProcess* process = new QProcess(this);
process->start(command);
}
EDIT Here the solution, if you need it:
Following the QStringList idea, my CallApp method just adds the command to the QStringList like:
list << command;
And then calls to Execute();
void FirstCase::Execute()
{
if(!list_.isEmpty()&&!executing_)
{
QProcess* p = new QProcess(this);
QString c = list_.takeFirst();
p->start(c);
executing_=TRUE;
connect(p, SIGNAL(finished(int)),this,SLOT(ExecFinished()));
}
}
void FirstCase::ExecFinished()
{
executing__=FALSE;
Execute();
}
You can use a QString queue to queue up your commands and store them. Then, start from the top of the queue, start a new process and connect its finished() signal to a slot. When that process finishes, start a new process if the queue is not empty and so forth.
The correct signature for finished
function is;
void QProcess::finished ( int exitCode, QProcess::ExitStatus exitStatus )
so you should connect like this;
connect(p, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(ExecFinished()));
精彩评论