-1

I am currently working on a project with Qt5.4 and C++. In this project I start and stop Processes with the QProcess class.

I am now extending the project to start batch files. The Problem is that I want to terminate/kill the processes started with the batch file, using the QProcess. Calling terminate does not work (or maybe I am calling it wrong)

edit: QProcess is a Member(pointer) of a class called ProcessHolder. startProcess() and stopProcess() handle the process.

bool ProcessHolder::startProcess(const QString &path, 
                                 const QStringList  &args) {
    process_->start(path, args);
    qDebug() << process_->errorString();
    if(process_->waitForStarted(1000)) {
        state_ = ProcessState::running;
        return true;
    } else {
        state_ = ProcessState::fail;
        return false;
    }
}

bool ProcessHolder::stopProcess() {
    process_->terminate();
    state_ = ProcessState::notRunning;
    return true;
}

Please help me, Ben

b.holz
  • 237
  • 3
  • 17
  • 2
    *"Calling terminate does not work"* - this depends on how you're calling QProcess. If, for example, you're using the static function QProcess::execute, then of-course it won't work. I suggest you show example code of what you're trying to do. – TheDarkKnight Jul 06 '15 at 14:34

1 Answers1

0

So Qt does not provide an anwser for this kind of problem. Windows seems to don't have a proper implementation of a process tree.

You can use CreateToolhelp32Snapshot to view all processes and there parent-processes.

then you have to build a tree and erase it by hand. You can use QProcess::processID() to get the root process for that tree.

b.holz
  • 237
  • 3
  • 17