user10733862
user10733862

Reputation:

Qt5: how to batch process by using QProcess

I want to let QProcess run many command at a time,instead of one at a time.

void Route::add_route()
{
    QProcess *Add_route = new QProcess(this);
    Add_route->start("notepad",QStringList() << "interface" << "ipv4" << "set" << "interface" << "" << "metric=1");
    Add_route->start("explorer",QStringList() << "interface" << "ipv6" << "set" << "interface" << "" << "metric=1");
    Add_route->waitForFinished();
}

By using this,it will only run the first one.
Ps: I'm using notepad and explorer just for test
Thanks!

Upvotes: 0

Views: 538

Answers (2)

Marek R
Marek R

Reputation: 37512

QProcess as name suggest represents single process not multiple. So your requirement to run two processes using single QProcess object is faulty by design.

You have two choices:

Upvotes: 0

markus-nm
markus-nm

Reputation: 865

QProcess has a member-function startDetached(). Use one QProcess for every process you need to start, not one QProcess for all processes. See http://doc.qt.io/qt-5/qprocess.html#startDetached

Upvotes: 2

Related Questions