0

I'm trying to implement something that basically mimics a terminal window with Qt using C++. The functionality should be very basic:

  • A QProcess is started.
  • Data is read from the QProcess and displayed in a QTextEdit.

The issue is that I want the user to be able to input within the SAME QTextEdit characters which could be written to the QProcess. That is, when the QProcess asks the user for input, I want a signal to be emitted that the process is waiting for an input so that the gui sets an anchor, user starts typing, and this selected text gets communicated (or written) to the process.

So how can I define such a signal, or would like to know if there's a simpler implementation to what I want.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Mo Kanj
  • 107
  • 7
  • Qt doesn't support this out of the box, and there doesn't seem to be an easy cross-platform way to do it. Generally, standard streams are regarded as generic communication channels that don't necessarily entail interactive exchange of data with a user over a terminal. There are some hacks however that one could employ to detect that a child process is waiting for input. See [here](https://stackoverflow.com/a/18108185) and [here](https://stackoverflow.com/a/49631900). However, they are fairly complicated and depend on platform-specific APIs. – Mike Sep 19 '20 at 12:03
  • I would strongly recommend to drop this auto-detection requirement, and either rely on the child process to print the prompt, or use a separate IPC mechanism to allow the child process to inform its parent process that it is waiting for user input (this could even be done by printing a special string to stdout/stderr, which the parent process detects and acts upon). If you have no control over the behavior of the child process, then there is probably no way but to explore those hacks. – Mike Sep 19 '20 at 12:09

0 Answers0