C++ 在QT C+中运行和终止进程+;通过按键
我正在尝试编写一个GUI,当按下一个按钮时,它将启动或停止一个进程。目前,我的代码甚至无法启动该过程,我一直坚持这一点。按钮单击,文本更改,但该过程不会执行,也不会出现错误消息。这是QMainWindow对象中按钮槽的代码:C++ 在QT C+中运行和终止进程+;通过按键,c++,qt,user-interface,process,qprocess,C++,Qt,User Interface,Process,Qprocess,我正在尝试编写一个GUI,当按下一个按钮时,它将启动或停止一个进程。目前,我的代码甚至无法启动该过程,我一直坚持这一点。按钮单击,文本更改,但该过程不会执行,也不会出现错误消息。这是QMainWindow对象中按钮槽的代码: void clickedSlot(){ QString s = "Record"; //switch between record and stop if(s!=((QPushButton*)sender())->
void clickedSlot(){
QString s = "Record";
//switch between record and stop
if(s!=((QPushButton*)sender())->text()){
((QPushButton*)sender())->setText("Record");
process->kill();
process->waitForFinished();
delete process;
}else{
((QPushButton*)sender())->setText("Stop");
process = new QProcess(this);
QString executable = "./record";
process->start(executable);
process->waitForStarted();
}
};
对于QProcess为什么不启动以及之后如何停止的任何帮助,我们将不胜感激。我确实在代码的顶部有一个#include问题可能在您(未)启动的可执行路径中。 请确保以下各项,然后重试:
- 你给了一个绝对的路径
- 您确保返回true
- 您可以使用process->readAllStandardOutput()和process->readAllStandardError()来检索程序的输出以进行调试
waitForStarted
返回值。如果进程未能启动,则该值应为false。确保record
可执行文件位于应用程序的工作目录中。您使用的是什么平台的OSX或Linux?正如JRG所说。和errorString()
。