简体   繁体   English

通过按下按钮在QT C ++中运行和终止进程

[英]Running and killing processes in QT C++ via button press

I am trying to write a GUI, that when a button is pressed, will either start or stop a process. 我试图编写一个GUI,当按下一个按钮时,它将启动或停止一个进程。 Currently, my code won't even start the process, and I am stuck to why that is. 目前,我的代码甚至都不会启动该过程,而我坚持这样做的原因。 The button clicks and the text changes, but the process doesn't execute and no error messages occur. 单击该按钮,文本更改,但是该过程没有执行,并且没有错误消息发生。 This is the code for the button slot in the QMainWindow object: 这是QMainWindow对象中按钮槽的代码:

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();
        }
};

Any help to why the QProcess doesn't start and how to stop it after would be greatly appreciated. 对于为什么QProcess无法启动以及如何停止之后的任何帮助,将不胜感激。 I do have a #include at the top of the code 我在代码顶部确实有一个#include

The problem may be in the executable path you are (not) starting. 问题可能出在(不是)您正在启动的可执行路径中。 Try again by making sure that: 请确保以下内容重试:

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

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