使用C++处理不同的应用程序

Handle different application using C++

本文关键字:应用程序 C++ 处理 使用      更新时间:2023-10-16

是否有任何方法可以使用c++/qt控制其他windows应用程序?

我有:1000个特定图像格式的文件和一个可以打开它们的应用程序。此应用程序可以使用"另存为…"功能将这些文件逐个保存为".JPEG"格式。我想自动做到这一点。

有什么技巧可以做到这一点吗?提前谢谢!

使用QT,您可以使用QProcess实例运行单独的进程。

特别假设您的外部应用程序接受输入参数(例如,要加载的文件路径和存储结果的文件路径)

QProcess shell;
QStringList argv;
//[setup argument-list]
shell.setProcessChannelMode(QProcess::MergedChannels);
shell.start(commandPath, argv); 
shell.waitForFinished();

请注意,QProcess可以用作IO流。这有助于与流程交互(例如检索进度信息):

shell.start(commandPath, argv); 
shell.waitForReadyRead();
while(shell.state() == QProcess::Running || !shell.atEnd()){
   auto s = shell.readLine()
   //[do something with the current line of the process output]
}
QProcess::ExitStatus es =  shell.exitStatus () ;

当然,外部流程必须接受输入参数,并通过其标准输出提供反馈,以解决您的问题。