简体   繁体   English

Qt5:如何使用QProcess批处理

[英]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. 我想让QProcess一次运行多个命令,而不是一次运行。

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! 谢谢!

QProcess has a member-function startDetached() . QProcess具有成员函数startDetached() Use one QProcess for every process you need to start, not one QProcess for all processes. 对于需要启动的每个进程,请使用一个QProcess,而不要对所有进程使用一个QProcess。 See http://doc.qt.io/qt-5/qprocess.html#startDetached 请参阅http://doc.qt.io/qt-5/qprocess.html#startDetached

QProcess as name suggest represents single process not multiple. 顾名思义, QProcess表示单个进程而不是多个进程。 So your requirement to run two processes using single QProcess object is faulty by design. 因此,您设计使用单个QProcess对象运行两个进程的要求是错误的。

You have two choices: 您有两种选择:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM