Important: Please read the Qt Code of Conduct -

QProcess reopens again after I killed it

  • I'm using Qt5 on Windows.

    I have two QProcess in my project, both QProcess run external programs with their own arguments.

    Both QProcess succesfully start(), and kill() "seems" to work also fine for both QProcess.
    I'm using kill() because I want to allow the user to push a stop button anytime he wants to.

    But I have a weird issue that happens only when I follow these steps:

    • Starting one of my both QProcess (_yolomark_img)-> The QProccess starts
    • kill() the QProcess -> The QProccess
    • Start the other QProcess (_train_darknet) -> BOTH QProcess starts

    I don't have this issue if I start the second QProcess without creating the first one or by doing the steps in an opposite order.

    Here is part of my code if it helps.

          std::cout << _names_file_path.toStdString() << std::endl;
          QStringList args;
          args << _input_folder_path << _output_folder_path << _names_file_path;
           _yolomark_img = new QProcess();
           _yolomark_img->start(_darknet_path, args);
          connect( _yolomark_img, &QProcess::stateChanged, this, &Label::yolomarkFinished);
          connect(_yolomark_img , &QProcess::errorOccurred, this, &Label::yolomarkFinishedErr);

    Pressing Esc kills the Process in the external programm.

    void Label::endThread(){
       INPUT ip;
       ip.type = INPUT_KEYBOARD; = 0; // hardware scan code for key = 0; = 0;
   = 0x1B; // virtual-key code for the "Esc" key = 0; // 0 for key press
       SendInput(1, &ip, sizeof(INPUT)); 
   = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
       SendInput(1, &ip, sizeof(INPUT));
    void  Label::yolomarkFinished(QProcess::ProcessState state){
       disconnect( _yolomark_img, &QProcess::stateChanged, this, &Label::yolomarkFinished);
       disconnect(_yolomark_img, &QProcess::errorOccurred, this, &Label::yolomarkFinishedErr);
       if (state==QProcess::NotRunning && _active_processes>0) --_active_processes;
       if (_active_processes == 0) {
          emit resultReady();}
    void  Label::yolomarkFinishedErr(QProcess::ProcessError error){
       std::cout << "Error in process: " << error << std::endl;
       if (error<2) emit yolomarkFinished(QProcess::NotRunning); //crash or fail to start

    And in the other class, where both QProcess are created.

    void Train::train()
    const_cast<char*>(_initial_weights_path.toStdString().c_str()), 1);
       QStringList args;
          args << "detector" << "train" << "C:\\tmp\\rnn_utils\\trainings\\" << "C:\\tmp\\rnn_utils\\yolov4.cfg" << _initial_weights_path << " -map";
       //yolomark gets activated in this f***king line 
       _train_darknet = new QProcess();
       connect(_train_darknet, &QProcess::stateChanged, this, &Train::trainFinished);
       connect(_train_darknet, &QProcess::errorOccurred, this, &Train::trainFinishedErr);

Log in to reply