title: How to update QPlainTextEdit in real time?
body: <p>I am very new to Qt.</p>
  <p>I created a widget with Run and Cancel button.
  Run launches a bash script via QProcess, and Cancel button is meant to send SIGINT signal to disrupt the process in bash (does not work properly).</p>
  <p>QProcess which launches the script is declared in my constructor and connected to append functions as:</p>
  <pre><code>runScript = new QProcess;
  connect(runScript , SIGNAL(readyReadStandardError()), this, SLOT(updateProcessError()));
  connect(runScript , SIGNAL(readyReadStandardOutput()), this, SLOT(updateProcessText()));
  </code></pre>
  <p>where appending slots are simply updating log and logError QPlainTextEdits (also fields of MyWidget class):</p>
  <pre><code>void MyWidget::updateProcessError()
  {
      QString output(runScript -&gt;readAllStandardError());
      errorLog-&gt;appendPlainText(output);
      errorLog-&gt;verticalScrollBar()-&gt;setValue(log-&gt;verticalScrollBar()-&gt;maximum());};
  
  void MyWidget::updateProcessText()
  {
      QString output(runScript -&gt;readAllStandardOutput());
      log-&gt;appendPlainText(output);
      log-&gt;verticalScrollBar()-&gt;setValue(log-&gt;verticalScrollBar()-&gt;maximum());
  };  
  </code></pre>
  <p>Now this does not work in real time. It does append all output, shell script is outputting on the terminal, along the errors, but only after script is finished.</p>
  <p>So while the script is running, everything is frozen, I cannot even click on Cancel button.</p>
  <p>So first question is: <strong>How to append QPlainTextEdit in real time, where appending is done by reading QProcess outputs from terminal?</strong></p>
  <p>I know why my Cancel button does not work and I have an idea for the solution. The Run button launches the <code>runScript</code> process and is waiting until it finishes. So naturally slot can't finish until script does. I feel the problem in my implementation is that I am trapping the Run button into QProcess that is running on the terminal. I could try to figure out a bash way to output script's output and errors to log files or fork the script execution and do something with its process, but I'd like an advice on how to do this properly (I only started with Qt 10 days ago so everything is new). I think if I run my script with &amp; in the end, I can somehow figure out how to get its id from qt (should be logged) and then Cancel button just needs to kill the process?
  This is how roughly slot for run button looks like:</p>
  <pre><code>void MyWidget::handleRunButton()
  {
      runButton-&gt;setEnabled(false);   
      QString program = &quot;MyShellScript &quot; + _scriptOptions;
      runScript-&gt;start(&quot;/bin/sh &quot; + program);
      runScript-&gt;waitForFinished(-1);
  }
  </code></pre>
  <p>I coded Cancel button to release SIGINT signal as:</p>
  <pre><code>void MyWidget::handleCancelButton()
  {
      QProcess *runCtrlC = new QProcess;
      runCtrlC-&gt;start(&quot;/bin/bash -c \&quot; kill -INT $$ \&quot; &quot;);
      runCtrlC-&gt;waitForFinished(-1);  
  
      runScript-&gt;terminate();
      emit finished(0);
  };
  </code></pre>
  <p>So my next question is, <strong>how to interrupt a running shell script from Qt on a button a click, that has started on another button click</strong>?</p>
  <p>I feel one solution is to launch script as separate process in bash on Run button click, and on Cancel button extract shell process id and kill it.
  If I do this, how would I then access output of process that is running the script in qt?
  I'd like the optimal answer.</p>