1.Qt的QProcess三种打开软件方式
start(),execute(),startDetached()
start():
start方法用于启动一个外部程序,它是异步的,意味着它会在启动进程后立即返回,不会阻塞调用线程。
使用start,你可以与进程交互,例如读取输出、写入输入、等待进程完成等。
可以指定进程的参数、环境变量,并且可以选择性地重定向标准输入输出。
start方法适用于需要与启动的进程进行通信或需要监控进程状态的情况。
execute():
execute方法也是用于启动一个外部程序,但它是以同步方式进行的,会阻塞调用线程直到外部程序执行完毕。
execute在内部调用start,然后等待进程结束,并返回进程的退出代码。
由于它是同步的,execute不适合需要与进程交互或不想阻塞主线程的应用程序。
execute不提供重定向标准输入输出的选项,也不允许在进程运行期间执行其他任务。
execute的使用比较简单,因为它会自动等待进程结束,并且返回退出代码。
startDetached():
startDetached方法用于在独立的进程中启动一个外部程序,它与父进程完全分离,不与父进程的QProcess实例进行通信,(这意味着无法使用信号-槽通信)。
startDetached 适用于启动那些不需要与父进程交互的独立应用程序。
使用 startDetached启动的进程有自己的控制台窗口(在 Windows 上),而 start和 execute启动的进程通常与父进程共享控制台。
startDetached不需要父进程等待子进程结束,子进程可以在父进程退出后继续运行。
2.设置简单过滤判断打开软件
QQstringList args;
args << "1" << "2" << "3";
QProcess myProcess;
myProcess.startDetached("文件地址+文件名", args);
3被开启的exe里的面函数
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStringList args = a.arguments();
if(args.count() < 4)
{
return 0;
}
int arg1 = args.at(1).toInt();
int arg2= args.at(2).toInt();
int arg3 = args.at(3).toInt();
if(arg1 + arg2 != arg3)
{
return 0;
}
MainWindow w;
w.show();
return a.exec();
}