I made a terminal by binding bash with QProcess:
// c++ in Qt4.8.7 on CentOS7
process_ptr->start("bash -i", QIODevice::ReadWrite | QIODevice::Append);
// With the "-i" option, interactive bash is able to display the *prompt*
Commands are entered through QCmdLine, fed to QProcess, and the output is printed to QPlainTextEdit
And I have merged the standard output channel with the standard error channel:
process_ptr->setProcessChannelMode(QProcess::MergedChannels);
The problem is: the command prompt(set by PS1) in QPlainTextEdit, which is used to display stdout or stderr, is messy.
Specifically, the content printed in QPlainTextEdit is as follows:
^[]0;eng@hostname:~^G[eng@hostname 15:36:41 #17 ~]$
ls
Desktop
Documents
Downloads
Music
Pictures
Public
Templates
Videos
^[]0;eng@hostname:~^G[eng@hostname 16:05:12 #18 ~]$
echo $PS1
[\u@\H \t #\# \W]\$
^[]0;eng@hostname:~^G[eng@hostname 16:05:35 #19 ~]$
^[]0;eng@hostname:~^G[eng@hostname 16:05:36 #19 ~]$
And I have set PS1 as
PS1="[\u@\H \t #\# \W]\$ "
It looks like the second half of the command prompt [eng@hostname 15:36:41 #17 ~]$ is what I set up correctly via PS1.
Now I don't know how to get rid of the first half ^[]0;eng@hostname:~^G, where ^[ denotes the ASCII control character "ESC" and ^G denotes the ASCII control character "BEL"
I've researched the concept of tty for this issue: my practice of binding a fixed bash via QProcess bypasses line discipline and pty, in other words input and output content is written/read directly to the bash process without going through line discipline and pty(Here's the link, it might be useful: tty/pty)
At the moment I'm not sure which module I should look at to locate the root cause of the problem: standard output/error channel redirection, the underlying principles of bash, QPlainTextEdit in Qt, etc.
Thank you very much for your valuable thoughts or solutions!