Creating a "terminal"
-
I'm trying to mimic a "terminal" for and IDE app I am creating. For example, I would like the output of my program to be displayed on the main Qt window. I also would like to be able to get user input from this same window.
In essence I am looking for something very similar to the "Application Output" pane of the QtCreator.
Any ideas on how this could be accomplished would me much appreciated :)
-
Hi and welcome to the forums
How many of the features do you need?
a QPlainTextEdit can be used to show text lines and also accept user input but
its not super "terminal" alike. So do you need to run "command" or in what
way terminal like? -
@Zeolitic
This gets asked several times. Depends what you want from it:-
A full terminal emulator/widget? If you don't want to write it yourself, or if you want to see how others do it to inspire you, there are several from Google
qt terminal emulator
. -
Is the "output of my program" stuff you write to
stdout
? Does input have to come fromstdin
? -
If you don't care about above, a
QTextEdit
can accept output from your program and accept input from the user.
I don't know if "the "Application Output" pane of the QtCreator." is available in itself.
-
-
Thanks for your quick replies!
I am looking just to output to the "terminal" and receive user input from the "terminal".
The "output of my program" is currently things that are being written to stdout, however I find this mess and would like to write to something inside the app. I don't care if it is received from stdin or written directly to stdout, I just care that I can send and receive input from this terminal.
Sounds like I have a good idea of where to start!
Any further ideas or examples you have are much appreciated.
-
Hi
So its more like a Debug view that actual a terminal ?
To get your output from stdout you can redirect it.
Like shown here
https://stackoverflow.com/questions/10308425/redirect-stdcout-to-a-qtextedit
Besides a QPlainTextEdit, you can use a LineEdit that is a single line edit
so if you place it under the PlainTextEdit, it can be a one liner input "prompt" and you can hook to its returnPressed signal to know when to react.All that said:
You do know qDebug() ?Small demo project with the code from link
https://www.dropbox.com/s/1i71xzx7c6xwdtw/SemiConsole.zip?dl=0MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); redirect = new QDebugStream(std::cout, ui ->textEdit); std::cout << "Send this to the Text Edit!" << std::endl; } MainWindow::~MainWindow() { delete redirect; delete ui; } void MainWindow::on_lineEdit_returnPressed() { std::cout << "COMMAND !!!" << std::endl; }
Note that sample uses TextEdit and not PlainTextEdit. Not that it matters much overall.
-
I'm making a my own custom coding language and and IDE to go along with it. So on my mainwindow currently I have a text edit where the user can write code and then compile it. The issues right now is that when the user prints anything, it appears in the console that my program was run in (because I am just using cout for the moment). However, I would like the output to be displayed in the same area the code is written.
I think what you've described above is perfect and is more than enough to get me started :)
-
@Zeolitic
Hi. Super.
later you might be interested in- Highligthing
https://doc.qt.io/qt-5/qtwidgets-richtext-syntaxhighlighter-example.html - line numbers
https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html
if you not already seen it. :)
- Highligthing